Skip to content

Commit 09b0ca4

Browse files
authoredOct 3, 2023
App Router - preinitialize chunks during SSR (#54752)
Today when we hydrate an SSR'd RSC response on the client we encounter import chunks which initiate code loading for client components. However we only start fetching these chunks after hydration has begun which is necessarily after the initial chunks for the entrypoint have loaded. React has upstream changes that need to land which will preinitialize the rendered chunks for all client components used during the SSR pass. This will cause a `<script async="" src... />` tag to be emitted in the head for each chunk we need to load during hydration which allows the browser to start fetching these resources even before the entrypoint has started to execute. Additionally the implementation for webpack and turbopack is different enough that there will be a new `react-server-dom-turbopack` package in the React repo which should be used when using Turbopack with Next. This PR also removes a number of patches to React src that proxy loading (`__next_chunk_load__`) and bundler requires (`__next_require__`) through the `globalThis` object. Now the react packages can be fully responsible for implementing chunk loading and all Next needs to do is supply the necessary information such as chunk prefix and crossOrigin attributes necessary for this loading. This information is produced as part of the client-manifest by either a Webpack plugin or Turbopack. Additionally any modifications to the chunk filename that were previously done at runtime need to be made in the manifest itself now. This means we need to encode the deployment id for skew protection and encode the filename to make it match our static path matching (and resolutions on s3) when using `[` and `]` segment characters. There are a few followup items to consider in later PRs 1. we currently bundle a node and edge version of react-server-dom-webpack/client. The node version has an implementation for busboy whereas the edge version does not. Next is currently configured to use busboy when handling a fetch action sent as multipart with a node runtime. Ideally we'd only bundle the one platform we are buliding for but some additional refactoring to support better forking is possibly required here This PR also updates react from 09285d5a7 to d900fadbf. ### React upstream changes - facebook/react#27439 - facebook/react#26763 - facebook/react#27434 - facebook/react#27433 - facebook/react#27424 - facebook/react#27428 - facebook/react#27427 - facebook/react#27315 - facebook/react#27314 - facebook/react#27400 - facebook/react#27421 - facebook/react#27419 - facebook/react#27418
1 parent e34fdf2 commit 09b0ca4

File tree

192 files changed

+60997
-8647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+60997
-8647
lines changed
 

‎package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@
192192
"random-seed": "0.3.0",
193193
"react": "18.2.0",
194194
"react-17": "npm:react@17.0.2",
195-
"react-builtin": "npm:react@18.3.0-canary-09285d5a7-20230925",
195+
"react-builtin": "npm:react@18.3.0-canary-d900fadbf-20230929",
196196
"react-dom": "18.2.0",
197197
"react-dom-17": "npm:react-dom@17.0.2",
198-
"react-dom-builtin": "npm:react-dom@18.3.0-canary-09285d5a7-20230925",
199-
"react-dom-experimental-builtin": "npm:react-dom@0.0.0-experimental-09285d5a7-20230925",
200-
"react-experimental-builtin": "npm:react@0.0.0-experimental-09285d5a7-20230925",
201-
"react-server-dom-webpack": "18.3.0-canary-09285d5a7-20230925",
202-
"react-server-dom-webpack-experimental": "npm:react-server-dom-webpack@0.0.0-experimental-09285d5a7-20230925",
198+
"react-dom-builtin": "npm:react-dom@18.3.0-canary-d900fadbf-20230929",
199+
"react-dom-experimental-builtin": "npm:react-dom@0.0.0-experimental-d900fadbf-20230929",
200+
"react-experimental-builtin": "npm:react@0.0.0-experimental-d900fadbf-20230929",
201+
"react-server-dom-turbopack": "18.3.0-canary-d900fadbf-20230929",
202+
"react-server-dom-turbopack-experimental": "npm:react-server-dom-webpack@0.0.0-experimental-d900fadbf-20230929",
203+
"react-server-dom-webpack": "18.3.0-canary-d900fadbf-20230929",
204+
"react-server-dom-webpack-experimental": "npm:react-server-dom-webpack@0.0.0-experimental-d900fadbf-20230929",
203205
"react-ssr-prepass": "1.0.8",
204206
"react-virtualized": "9.22.3",
205207
"relay-compiler": "13.0.2",
@@ -209,8 +211,8 @@
209211
"resolve-from": "5.0.0",
210212
"sass": "1.54.0",
211213
"satori": "0.10.6",
212-
"scheduler-builtin": "npm:scheduler@0.24.0-canary-09285d5a7-20230925",
213-
"scheduler-experimental-builtin": "npm:scheduler@0.0.0-experimental-09285d5a7-20230925",
214+
"scheduler-builtin": "npm:scheduler@0.24.0-canary-d900fadbf-20230929",
215+
"scheduler-experimental-builtin": "npm:scheduler@0.0.0-experimental-d900fadbf-20230929",
214216
"seedrandom": "3.0.5",
215217
"selenium-webdriver": "4.0.0-beta.4",
216218
"semver": "7.3.7",

‎packages/next-swc/crates/next-api/src/app.rs

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl AppProject {
212212
"next-dynamic".to_string(),
213213
Vc::upcast(NextDynamicTransition::new(self.client_transition())),
214214
),
215+
("next-ssr".to_string(), Vc::upcast(self.ssr_transition())),
215216
]
216217
.into_iter()
217218
.collect();
@@ -636,6 +637,10 @@ impl AppEndpoint {
636637
client_references_chunks,
637638
this.app_project.project().client_chunking_context(),
638639
Vc::upcast(this.app_project.project().ssr_chunking_context()),
640+
this.app_project
641+
.project()
642+
.next_config()
643+
.computed_asset_prefix(),
639644
);
640645
server_assets.push(entry_manifest);
641646
}

0 commit comments

Comments
 (0)
Please sign in to comment.