Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port page and layout level API assertions to SWC transform (#40653)
We used to do an extra pass of SWR `parse` and loop over the AST inside JavaScript to check if `getServerSideProps` or `getStaticProps` is used in a client page or layout. Instead this can be done in the same `react_server_components` SWC transform now. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
- Loading branch information
Showing
10 changed files
with
139 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...tes/core/tests/errors/react-server-components/client-graph/get-server-side-props/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function getServerSideProps (){ | ||
} | ||
|
||
export default function () { | ||
return null; | ||
} |
4 changes: 4 additions & 0 deletions
4
...es/core/tests/errors/react-server-components/client-graph/get-server-side-props/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function getServerSideProps() {} | ||
export default function() { | ||
return null; | ||
} |
6 changes: 6 additions & 0 deletions
6
...ore/tests/errors/react-server-components/client-graph/get-server-side-props/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
x `getServerSideProps` is not allowed in Client Components. | ||
,-[input.js:1:1] | ||
1 | export function getServerSideProps (){ | ||
: ^^^^^^^^^^^^^^^^^^ | ||
`---- |
6 changes: 6 additions & 0 deletions
6
...c/crates/core/tests/errors/react-server-components/client-graph/get-static-props/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function getStaticProps (){ | ||
} | ||
|
||
export default function () { | ||
return null; | ||
} |
4 changes: 4 additions & 0 deletions
4
.../crates/core/tests/errors/react-server-components/client-graph/get-static-props/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function getStaticProps() {} | ||
export default function() { | ||
return null; | ||
} |
6 changes: 6 additions & 0 deletions
6
...tes/core/tests/errors/react-server-components/client-graph/get-static-props/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
x `getStaticProps` is not allowed in Client Components. | ||
,-[input.js:1:1] | ||
1 | export function getStaticProps (){ | ||
: ^^^^^^^^^^^^^^ | ||
`---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters