-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of statically optimized flight data of server component pages #35619
Merged
Conversation
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 comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
shuding
commented
Mar 29, 2022
Comment on lines
+558
to
+560
startTransition(() => { | ||
reactRoot.render(reactEl) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps address the https://reactjs.org/docs/error-decoder.html/?invariant=426 error.
This comment has been minimized.
This comment has been minimized.
shuding
requested review from
timneutkens,
ijjk,
padmaia and
huozhi
as code owners
March 29, 2022 15:50
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
huozhi
reviewed
Mar 31, 2022
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
huozhi
reviewed
Apr 1, 2022
huozhi
approved these changes
Apr 1, 2022
This comment has been minimized.
This comment has been minimized.
Stats from current PRDefault Build (Decrease detected ✓)General Overall increase
|
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
buildDuration | 20.3s | 20.2s | -126ms |
buildDurationCached | 7.8s | 7.6s | -181ms |
nodeModulesSize | 477 MB | 477 MB |
Page Load Tests Overall decrease ⚠️
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 4.403 | 4.401 | 0 |
/ avg req/sec | 567.79 | 568.1 | +0.31 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 2.115 | 2.142 | |
/error-in-render avg req/sec | 1182.01 | 1167.29 |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
925.HASH.js gzip | 179 B | 179 B | ✓ |
framework-HASH.js gzip | 42 kB | 42 kB | ✓ |
main-HASH.js gzip | 28.4 kB | 28.4 kB | |
webpack-HASH.js gzip | 1.44 kB | 1.44 kB | ✓ |
Overall change | 72.1 kB | 72.1 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.36 kB | 1.36 kB | ✓ |
_error-HASH.js gzip | 192 B | 192 B | ✓ |
amp-HASH.js gzip | 309 B | 309 B | ✓ |
css-HASH.js gzip | 327 B | 327 B | ✓ |
dynamic-HASH.js gzip | 3.05 kB | 3.05 kB | ✓ |
head-HASH.js gzip | 351 B | 351 B | ✓ |
hooks-HASH.js gzip | 920 B | 920 B | ✓ |
image-HASH.js gzip | 5.48 kB | 5.48 kB | ✓ |
index-HASH.js gzip | 263 B | 263 B | ✓ |
link-HASH.js gzip | 2.26 kB | 2.26 kB | ✓ |
routerDirect..HASH.js gzip | 320 B | 320 B | ✓ |
script-HASH.js gzip | 387 B | 387 B | ✓ |
withRouter-HASH.js gzip | 319 B | 319 B | ✓ |
85e02e95b279..7e3.css gzip | 107 B | 107 B | ✓ |
Overall change | 15.7 kB | 15.7 kB | ✓ |
Client Build Manifests
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
_buildManifest.js gzip | 460 B | 460 B | ✓ |
Overall change | 460 B | 460 B | ✓ |
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
index.html gzip | 532 B | 531 B | -1 B |
link.html gzip | 546 B | 545 B | -1 B |
withRouter.html gzip | 526 B | 525 B | -1 B |
Overall change | 1.6 kB | 1.6 kB | -3 B |
Diffs
Diff for main-HASH.js
@@ -1177,7 +1177,7 @@
shouldHydrate ? markHydrateComplete : markRenderComplete
);
if (false) {
- var ReactDOMClient;
+ var startTransition, ReactDOMClient;
} else {
// The check for `.hydrate` is there to support React alternatives like preact
if (shouldHydrate) {
@@ -1318,7 +1318,9 @@
initialServerDataWriter,
initialServerDataBuffer,
encoder,
+ ref1,
createFromFetch,
+ createFromReadableStream,
getCacheKey,
useServerResponse,
fetchFlight,
@@ -1679,7 +1681,7 @@
var href = param.href,
asPath = param.asPath,
ssg = param.ssg,
- rsc = param.rsc,
+ flight = param.flight,
locale = param.locale;
var _this = this;
var ref = (0, _parseRelativeUrl).parseRelativeUrl(href),
@@ -1690,7 +1692,7 @@
asPathname = ref1.pathname;
var route = normalizeRoute(hrefPathname);
var getHrefForSlug = function(path) {
- if (rsc) {
+ if (flight) {
return path + search + (search ? "&" : "?") + "__flight__=1";
}
var dataRoute = (0, _getAssetPathFromRoute).default(
@@ -5869,10 +5871,10 @@
__N_RSC,
isValidElementType,
dataHref,
+ useStreamedFlightData,
props,
- ref,
- fresh,
- data;
+ data,
+ __flight__;
return _runtimeJs.default.wrap(
function _callee$(_ctx) {
while (1)
@@ -5951,6 +5953,8 @@
)
);
case 17:
+ useStreamedFlightData =
+ (false || __N_SSP) && __N_RSC;
if (__N_SSG || __N_SSP || __N_RSC) {
dataHref = _this.pageLoader.getDataHref({
href: (0, _formatUrl).formatWithValidation({
@@ -5959,13 +5963,14 @@
}),
asPath: resolvedAs,
ssg: __N_SSG,
- rsc: __N_RSC,
+ flight: useStreamedFlightData,
locale: locale
});
}
- _ctx.next = 21;
+ _ctx.next = 22;
return _this._getData(function() {
- return __N_SSG || __N_SSP
+ return (__N_SSG || __N_SSP || __N_RSC) &&
+ !useStreamedFlightData
? fetchNextData(
dataHref,
_this.isSsr,
@@ -5982,30 +5987,43 @@
defaultLocale: _this.defaultLocale
});
});
- case 21:
+ case 22:
props = _ctx.sent;
if (!__N_RSC) {
- _ctx.next = 29;
+ _ctx.next = 32;
break;
}
- _ctx.next = 25;
+ if (!useStreamedFlightData) {
+ _ctx.next = 31;
+ break;
+ }
+ _ctx.next = 27;
return _this._getData(function() {
return _this._getFlightData(dataHref);
});
- case 25:
- ref = _ctx.sent;
- fresh = ref.fresh;
- data = ref.data;
+ case 27:
+ data = _ctx.sent.data;
props.pageProps = Object.assign(props.pageProps, {
- __flight_serialized__: data,
- __flight_fresh__: fresh
+ __flight__: data
});
- case 29:
+ _ctx.next = 32;
+ break;
+ case 31: {
+ __flight__ = props.__flight__;
+ props.pageProps = Object.assign(
+ {},
+ props.pageProps,
+ {
+ __flight__: __flight__
+ }
+ );
+ }
+ case 32:
routeInfo.props = props;
_this.components[route] = routeInfo;
return _ctx.abrupt("return", routeInfo);
- case 34:
- _ctx.prev = 34;
+ case 37:
+ _ctx.prev = 37;
_ctx.t1 = _ctx["catch"](0);
return _ctx.abrupt(
"return",
@@ -6017,14 +6035,14 @@
routeProps
)
);
- case 37:
+ case 40:
case "end":
return _ctx.stop();
}
},
_callee,
null,
- [[0, 34]]
+ [[0, 37]]
);
})
)();
@@ -6363,7 +6381,6 @@
return fetchNextData(dataHref, true, true, this.sdc, false).then(
function(serialized) {
return {
- fresh: true,
data: serialized
};
}
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-c0f54c07c3697931.js"
+ src="/_next/static/chunks/main-2413143f15cbe12b.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-c0f54c07c3697931.js"
+ src="/_next/static/chunks/main-2413143f15cbe12b.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-c0f54c07c3697931.js"
+ src="/_next/static/chunks/main-2413143f15cbe12b.js"
defer=""
></script>
<script
Default Build with SWC (Increase detected ⚠️ )
General Overall increase ⚠️
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
buildDuration | 23.9s | 24.5s | |
buildDurationCached | 8.1s | 7.7s | -417ms |
nodeModulesSize | 477 MB | 477 MB |
Page Load Tests Overall decrease ⚠️
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 4.44 | 4.363 | -0.08 |
/ avg req/sec | 563.11 | 573 | +9.89 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 2.08 | 2.195 | |
/error-in-render avg req/sec | 1201.94 | 1139.15 |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
925.HASH.js gzip | 178 B | 178 B | ✓ |
framework-HASH.js gzip | 42.3 kB | 42.3 kB | ✓ |
main-HASH.js gzip | 28.8 kB | 28.8 kB | |
webpack-HASH.js gzip | 1.45 kB | 1.45 kB | ✓ |
Overall change | 72.7 kB | 72.7 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.35 kB | 1.35 kB | ✓ |
_error-HASH.js gzip | 179 B | 179 B | ✓ |
amp-HASH.js gzip | 313 B | 313 B | ✓ |
css-HASH.js gzip | 325 B | 325 B | ✓ |
dynamic-HASH.js gzip | 3.03 kB | 3.03 kB | ✓ |
head-HASH.js gzip | 351 B | 351 B | ✓ |
hooks-HASH.js gzip | 921 B | 921 B | ✓ |
image-HASH.js gzip | 5.59 kB | 5.59 kB | ✓ |
index-HASH.js gzip | 261 B | 261 B | ✓ |
link-HASH.js gzip | 2.33 kB | 2.33 kB | ✓ |
routerDirect..HASH.js gzip | 322 B | 322 B | ✓ |
script-HASH.js gzip | 388 B | 388 B | ✓ |
withRouter-HASH.js gzip | 317 B | 317 B | ✓ |
85e02e95b279..7e3.css gzip | 107 B | 107 B | ✓ |
Overall change | 15.8 kB | 15.8 kB | ✓ |
Client Build Manifests
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
_buildManifest.js gzip | 459 B | 459 B | ✓ |
Overall change | 459 B | 459 B | ✓ |
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary | shuding/next.js shu/dced | Change | |
---|---|---|---|
index.html gzip | 532 B | 532 B | ✓ |
link.html gzip | 545 B | 546 B | |
withRouter.html gzip | 527 B | 527 B | ✓ |
Overall change | 1.6 kB | 1.6 kB |
Diffs
Diff for main-HASH.js
@@ -1177,7 +1177,7 @@
shouldHydrate ? markHydrateComplete : markRenderComplete
);
if (false) {
- var ReactDOMClient;
+ var startTransition, ReactDOMClient;
} else {
// The check for `.hydrate` is there to support React alternatives like preact
if (shouldHydrate) {
@@ -1318,7 +1318,9 @@
initialServerDataWriter,
initialServerDataBuffer,
encoder,
+ ref1,
createFromFetch,
+ createFromReadableStream,
getCacheKey,
useServerResponse,
fetchFlight,
@@ -1679,7 +1681,7 @@
var href = param.href,
asPath = param.asPath,
ssg = param.ssg,
- rsc = param.rsc,
+ flight = param.flight,
locale = param.locale;
var _this = this;
var ref = (0, _parseRelativeUrl).parseRelativeUrl(href),
@@ -1690,7 +1692,7 @@
asPathname = ref1.pathname;
var route = normalizeRoute(hrefPathname);
var getHrefForSlug = function(path) {
- if (rsc) {
+ if (flight) {
return path + search + (search ? "&" : "?") + "__flight__=1";
}
var dataRoute = (0, _getAssetPathFromRoute).default(
@@ -5869,10 +5871,10 @@
__N_RSC,
isValidElementType,
dataHref,
+ useStreamedFlightData,
props,
- ref,
- fresh,
- data;
+ data,
+ __flight__;
return _runtimeJs.default.wrap(
function _callee$(_ctx) {
while (1)
@@ -5951,6 +5953,8 @@
)
);
case 17:
+ useStreamedFlightData =
+ (false || __N_SSP) && __N_RSC;
if (__N_SSG || __N_SSP || __N_RSC) {
dataHref = _this.pageLoader.getDataHref({
href: (0, _formatUrl).formatWithValidation({
@@ -5959,13 +5963,14 @@
}),
asPath: resolvedAs,
ssg: __N_SSG,
- rsc: __N_RSC,
+ flight: useStreamedFlightData,
locale: locale
});
}
- _ctx.next = 21;
+ _ctx.next = 22;
return _this._getData(function() {
- return __N_SSG || __N_SSP
+ return (__N_SSG || __N_SSP || __N_RSC) &&
+ !useStreamedFlightData
? fetchNextData(
dataHref,
_this.isSsr,
@@ -5982,30 +5987,43 @@
defaultLocale: _this.defaultLocale
});
});
- case 21:
+ case 22:
props = _ctx.sent;
if (!__N_RSC) {
- _ctx.next = 29;
+ _ctx.next = 32;
break;
}
- _ctx.next = 25;
+ if (!useStreamedFlightData) {
+ _ctx.next = 31;
+ break;
+ }
+ _ctx.next = 27;
return _this._getData(function() {
return _this._getFlightData(dataHref);
});
- case 25:
- ref = _ctx.sent;
- fresh = ref.fresh;
- data = ref.data;
+ case 27:
+ data = _ctx.sent.data;
props.pageProps = Object.assign(props.pageProps, {
- __flight_serialized__: data,
- __flight_fresh__: fresh
+ __flight__: data
});
- case 29:
+ _ctx.next = 32;
+ break;
+ case 31: {
+ __flight__ = props.__flight__;
+ props.pageProps = Object.assign(
+ {},
+ props.pageProps,
+ {
+ __flight__: __flight__
+ }
+ );
+ }
+ case 32:
routeInfo.props = props;
_this.components[route] = routeInfo;
return _ctx.abrupt("return", routeInfo);
- case 34:
- _ctx.prev = 34;
+ case 37:
+ _ctx.prev = 37;
_ctx.t1 = _ctx["catch"](0);
return _ctx.abrupt(
"return",
@@ -6017,14 +6035,14 @@
routeProps
)
);
- case 37:
+ case 40:
case "end":
return _ctx.stop();
}
},
_callee,
null,
- [[0, 34]]
+ [[0, 37]]
);
})
)();
@@ -6363,7 +6381,6 @@
return fetchNextData(dataHref, true, true, this.sdc, false).then(
function(serialized) {
return {
- fresh: true,
data: serialized
};
}
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-c0f54c07c3697931.js"
+ src="/_next/static/chunks/main-2413143f15cbe12b.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-c0f54c07c3697931.js"
+ src="/_next/static/chunks/main-2413143f15cbe12b.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-c0f54c07c3697931.js"
+ src="/_next/static/chunks/main-2413143f15cbe12b.js"
defer=""
></script>
<script
ijjk
approved these changes
Apr 1, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Part of #31506 and #34179. This PR ensures that in the
nodejs
runtime, the flight data is statically stored as a JSON file if possible. Most of the touched code is related to conditions of static/SSG/SSR when runtime and/or RSC is involved.Bug
fixes #number
contributing.md
Feature
fixes #number
contributing.md
Documentation / Examples
yarn lint