Skip to content
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

[Flight] Support postponing through a serialized promise #27818

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Dec 8, 2023

Postponing in a promise that is being serialized to the client from the server should be possible however prior to this change Flight treated this case like an error rather than a postpone. This fix adds support for postponing in this position and adds a test asserting you can successfully prerender the root if you unwrap this promise inside a suspense boundary.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Dec 8, 2023
Comment on lines 410 to 426
if (
enablePostpone &&
typeof reason === 'object' &&
reason !== null &&
(reason: any).$$typeof === REACT_POSTPONE_TYPE
) {
const postponeInstance: Postpone = (reason: any);
logPostpone(request, postponeInstance.message);
emitPostponeChunk(request, newTask.id, postponeInstance);
} else {
newTask.status = ERRORED;
const digest = logRecoverableError(request, reason);
emitErrorChunk(request, newTask.id, digest, reason);
}
if (request.destination !== null) {
flushCompletedChunks(request, request.destination);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just an oversight before? The lack of parity between the already resolved pathway and the delayed resolve pathway seems so glaring I worry I misunderstand how this is supposed to work. That said without some deeper reasoning why it has to work differently this seems like a quite straight forward fix

@gnoff gnoff force-pushed the investigate-postpone-onerror branch from 18fff5d to 009eef4 Compare December 8, 2023 18:15
@react-sizebot
Copy link

react-sizebot commented Dec 8, 2023

Comparing: d3ed07b...b36305c

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 175.90 kB 175.90 kB = 54.75 kB 54.75 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 177.97 kB 177.97 kB = 55.39 kB 55.39 kB
facebook-www/ReactDOM-prod.classic.js = 569.92 kB 569.92 kB = 100.31 kB 100.31 kB
facebook-www/ReactDOM-prod.modern.js = 553.77 kB 553.77 kB = 97.40 kB 97.40 kB
test_utils/ReactAllWarnings.js Deleted 67.17 kB 0.00 kB Deleted 16.35 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-server/cjs/react-server-flight.production.min.js +0.38% 19.59 kB 19.66 kB +0.07% 6.86 kB 6.87 kB
oss-experimental/react-server/cjs/react-server-flight.production.js +0.29% 67.27 kB 67.47 kB +0.08% 15.78 kB 15.80 kB
oss-experimental/react-server/cjs/react-server-flight.development.js +0.28% 78.08 kB 78.30 kB +0.08% 18.41 kB 18.43 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +0.26% 28.70 kB 28.77 kB +0.14% 9.68 kB 9.70 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.production.min.js +0.25% 29.48 kB 29.56 kB +0.10% 9.80 kB 9.81 kB
oss-experimental/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.production.min.js +0.25% 29.60 kB 29.67 kB +0.13% 9.88 kB 9.89 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.production.min.js +0.25% 29.80 kB 29.87 kB +0.18% 9.90 kB 9.92 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +0.25% 30.23 kB 30.31 kB +0.07% 10.00 kB 10.01 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +0.25% 30.33 kB 30.40 kB +0.17% 10.10 kB 10.12 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +0.25% 30.43 kB 30.51 kB +0.11% 10.06 kB 10.07 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.production.min.js +0.24% 30.74 kB 30.81 kB +0.06% 10.25 kB 10.26 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.production.min.js +0.24% 31.23 kB 31.31 kB +0.04% 10.41 kB 10.41 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +0.24% 31.53 kB 31.61 kB +0.11% 10.45 kB 10.46 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.23% 32.04 kB 32.11 kB +0.14% 10.61 kB 10.62 kB
test_utils/ReactAllWarnings.js Deleted 67.17 kB 0.00 kB Deleted 16.35 kB 0.00 kB

Generated by 🚫 dangerJS against b36305c

@gnoff gnoff force-pushed the investigate-postpone-onerror branch 5 times, most recently from 5a1b141 to de4ecdb Compare December 8, 2023 18:32
…he server should be possible however prior to this change Flight treated this case like an error rather than a postpone. This fix adds support for postponing in this position and adds a test asserting you can successfully prerender the root if you unwrap this promise inside a suspense boundary.
@gnoff gnoff force-pushed the investigate-postpone-onerror branch from de4ecdb to b36305c Compare December 8, 2023 18:55
@gnoff gnoff merged commit 5bcade5 into facebook:main Dec 8, 2023
36 checks passed
@gnoff gnoff deleted the investigate-postpone-onerror branch December 8, 2023 19:05
github-actions bot pushed a commit that referenced this pull request Dec 8, 2023
Postponing in a promise that is being serialized to the client from the
server should be possible however prior to this change Flight treated
this case like an error rather than a postpone. This fix adds support
for postponing in this position and adds a test asserting you can
successfully prerender the root if you unwrap this promise inside a
suspense boundary.

DiffTrain build for [5bcade5](5bcade5)
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
)

Postponing in a promise that is being serialized to the client from the
server should be possible however prior to this change Flight treated
this case like an error rather than a postpone. This fix adds support
for postponing in this position and adds a test asserting you can
successfully prerender the root if you unwrap this promise inside a
suspense boundary.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
Postponing in a promise that is being serialized to the client from the
server should be possible however prior to this change Flight treated
this case like an error rather than a postpone. This fix adds support
for postponing in this position and adds a test asserting you can
successfully prerender the root if you unwrap this promise inside a
suspense boundary.

DiffTrain build for commit 5bcade5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants