Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bundling and module resolution in the server layer (#40818)
We currently resolve the `react-server` condition correctly inside `externals` for the server layer, however that will cause the resolved path to be external (as it is called "externals"). So we need a way to hook into the module resolution process to force it to use the `react-server` condition **when it's on the server layer**. The `resolve` option doesn't give us that ability, and the solution in this PR is to leverage `normalModuleFactory`'s resolve hook to override the resolve options before actually resolving it. And there we can have the `contextInfo`. One thing left out is bundling for the edge server, we need to add tests and sort that out carefully. ## 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
4 changed files
with
71 additions
and
43 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
5 changes: 4 additions & 1 deletion
5
test/e2e/app-dir/rsc-basic/node_modules_bak/conditional-exports/index.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 |
---|---|---|
@@ -1 +1,4 @@ | ||
module.exports = 'index.default' | ||
const react = require('react') | ||
|
||
module.exports = | ||
'index.default:' + ('useState' in react ? 'react.full' : 'react.subset') |
5 changes: 4 additions & 1 deletion
5
test/e2e/app-dir/rsc-basic/node_modules_bak/conditional-exports/index.server.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 |
---|---|---|
@@ -1 +1,4 @@ | ||
module.exports = 'index.react-server' | ||
const react = require('react') | ||
|
||
module.exports = | ||
'index.react-server:' + ('useState' in react ? 'react.full' : 'react.subset') |