Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Should resolve esm external module imports on server (#40865)
### Issue When import an esm package in client component, and use it in server component page, it will fail to SSR but render successfully on client. It's because the import to esm package will make the client chunk become an **async module** since esm module will be treated as **async**. ``` page (serve component) -> local module (client) -> external dependency (esm) ``` Then in react SSR layer, it need the module type information of that chunk, async or not for react so that react could unwrap the async module from `Promise` properly when SSR. ### Solution We need to mark the client entries which are effected by async/esm modules that becoming **async** as `async: true` in SSR manifest. Since flight manifest plugin is only running against client compiler, which doesn't have those module information from server compiler. So we collect the async modules from the **server** compiler **client** layer from flight entry client plugin, then leverage the collection to detect if a module is async in flight manifest plugin for react. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md`
- Loading branch information
Showing
8 changed files
with
87 additions
and
54 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
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
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
3 changes: 2 additions & 1 deletion
3
test/e2e/app-dir/rsc-basic/node_modules_bak/random-module-instance/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,2 @@ | ||
exports.random = ~~(Math.random() * 1e5) | ||
export const random = ~~(Math.random() * 1e5) | ||
export const name = 'random-module-instance' |
3 changes: 2 additions & 1 deletion
3
test/e2e/app-dir/rsc-basic/node_modules_bak/random-module-instance/package.json
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,4 +1,5 @@ | ||
{ | ||
"name": "random-module-instance", | ||
"main": "./index.js" | ||
"type": "module", | ||
"exports": "./index.js" | ||
} |