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

[Fizz] Track postpones in fallbacks #27421

Merged
merged 2 commits into from
Sep 25, 2023

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Sep 25, 2023

This fixes so that you can postpone in a fallback. This postpones the parent boundary. I track the fallbacks in a separate replay node so that when we resume, we can replay the fallback itself and finish the fallback and then possibly later the content. By doing this we also ensure we don't complete the parent too early since now it has a render task on it.

There is one case that this surfaces that isn't limited to prerender/resume but also render/hydrateRoot. I left todos in the tests for this.

If you postpone in a fallback, and suspend in the content but eventually don't postpone in the content then we should be able to just skip postponing since the content rendered and we no longer need the fallback. This is a bit of a weird edge case though since fallbacks are supposed to be very minimal.

This happens because in both cases the fallback starts rendering early as soon as the content suspends. This also ensures that the parent doesn't complete early by increasing the blocking tasks. Unfortunately, the fallback will irreversibly postpone its parent boundary as soon as it hits a postpone.

When you suspend, the same thing happens but we typically deal with this by doing a "soft" abort on the fallback since we don't need it anymore which unblocks the parent boundary. We can't do that with postpone right now though since it's considered a terminal state.

I think I'll just leave this as is for now since it's an edge case but it's an annoying exception in the model. Makes me feel I haven't quite nailed it just yet.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 25, 2023
@@ -940,8 +963,7 @@ function renderSuspenseBoundary(
parentBoundary,
boundarySegment,
fallbackAbortSet,
// TODO: Should distinguish key path of fallback and primary tasks
keyPath,
fallbackKeyPath,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should also solve the edge case of useFormState inside a fallback sharing keys.

@react-sizebot
Copy link

react-sizebot commented Sep 25, 2023

Comparing: 430e712...c1bc974

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 = 167.45 kB 167.45 kB = 52.15 kB 52.15 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 176.11 kB 176.11 kB = 54.84 kB 54.84 kB
facebook-www/ReactDOM-prod.classic.js = 563.33 kB 563.33 kB = 99.28 kB 99.28 kB
facebook-www/ReactDOM-prod.modern.js = 547.06 kB 547.06 kB = 96.35 kB 96.35 kB
oss-experimental/react-server/cjs/react-server.production.min.js +2.05% 36.74 kB 37.50 kB +2.03% 11.48 kB 11.71 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.production.min.js +2.05% 36.74 kB 37.50 kB +2.03% 11.48 kB 11.71 kB
oss-stable-semver/react-server/cjs/react-server.production.min.js +1.96% 33.33 kB 33.98 kB +1.88% 10.51 kB 10.71 kB
oss-stable/react-server/cjs/react-server.production.min.js +1.96% 33.33 kB 33.98 kB +1.88% 10.51 kB 10.71 kB
facebook-www/ReactDOMServer-prod.classic.js +1.86% 174.68 kB 177.92 kB +1.34% 31.84 kB 32.26 kB
oss-experimental/react-server/cjs/react-server.development.js +1.48% 196.55 kB 199.46 kB +1.07% 45.60 kB 46.09 kB
oss-stable-semver/react-server/cjs/react-server.development.js +1.47% 178.91 kB 181.54 kB +0.99% 41.49 kB 41.90 kB
oss-stable/react-server/cjs/react-server.development.js +1.47% 178.91 kB 181.54 kB +0.99% 41.49 kB 41.90 kB
facebook-www/ReactDOMServer-prod.modern.js +1.33% 173.75 kB 176.05 kB +1.05% 31.59 kB 31.93 kB
facebook-www/ReactDOMServerStreaming-prod.modern.js +1.28% 181.75 kB 184.08 kB +0.95% 33.54 kB 33.86 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +1.00% 72.98 kB 73.71 kB +1.05% 22.27 kB 22.51 kB
oss-experimental/react-dom/umd/react-dom-server-legacy.browser.production.min.js +1.00% 73.13 kB 73.86 kB +1.02% 22.62 kB 22.85 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.production.min.js +0.96% 77.79 kB 78.54 kB +1.09% 23.85 kB 24.11 kB
oss-experimental/react-dom/umd/react-dom-server.browser.production.min.js +0.96% 77.92 kB 78.67 kB +1.11% 24.20 kB 24.47 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +0.96% 66.37 kB 67.01 kB +1.05% 19.74 kB 19.95 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.browser.production.min.js +0.96% 66.40 kB 67.03 kB +1.05% 19.77 kB 19.97 kB
oss-stable-semver/react-dom/umd/react-dom-server-legacy.browser.production.min.js +0.96% 66.53 kB 67.17 kB +1.02% 20.10 kB 20.30 kB
oss-stable/react-dom/umd/react-dom-server-legacy.browser.production.min.js +0.96% 66.56 kB 67.20 kB +1.03% 20.12 kB 20.33 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.production.min.js +0.95% 77.04 kB 77.77 kB +1.04% 23.37 kB 23.61 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.node.production.min.js +0.93% 78.92 kB 79.65 kB +1.09% 24.13 kB 24.39 kB
oss-stable-semver/react-dom/cjs/react-dom-server.browser.production.min.js +0.92% 69.09 kB 69.72 kB +0.94% 21.20 kB 21.40 kB
oss-stable/react-dom/cjs/react-dom-server.browser.production.min.js +0.92% 69.11 kB 69.75 kB +0.94% 21.23 kB 21.42 kB
oss-experimental/react-dom/cjs/react-dom-server.node.production.min.js +0.92% 81.27 kB 82.02 kB +0.96% 24.81 kB 25.05 kB
oss-stable-semver/react-dom/umd/react-dom-server.browser.production.min.js +0.92% 69.23 kB 69.87 kB +0.89% 21.50 kB 21.69 kB
oss-stable/react-dom/umd/react-dom-server.browser.production.min.js +0.92% 69.26 kB 69.89 kB +0.88% 21.52 kB 21.71 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.production.min.js +0.90% 83.06 kB 83.81 kB +1.02% 25.59 kB 25.85 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.node.production.min.js +0.88% 71.91 kB 72.54 kB +0.93% 21.55 kB 21.75 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.node.production.min.js +0.88% 71.93 kB 72.57 kB +0.93% 21.58 kB 21.78 kB
oss-stable-semver/react-dom/cjs/react-dom-server.bun.production.min.js +0.88% 72.08 kB 72.71 kB +0.91% 21.75 kB 21.95 kB
oss-stable/react-dom/cjs/react-dom-server.bun.production.min.js +0.88% 72.10 kB 72.74 kB +0.92% 21.78 kB 21.98 kB
oss-stable-semver/react-dom/cjs/react-dom-server.edge.production.min.js +0.86% 73.97 kB 74.61 kB +0.83% 22.74 kB 22.93 kB
oss-stable/react-dom/cjs/react-dom-server.edge.production.min.js +0.86% 74.00 kB 74.63 kB +0.83% 22.77 kB 22.96 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node.production.min.js +0.86% 74.05 kB 74.68 kB +0.82% 22.82 kB 23.01 kB
oss-stable/react-dom/cjs/react-dom-server.node.production.min.js +0.86% 74.07 kB 74.71 kB +0.81% 22.85 kB 23.03 kB
oss-experimental/react-dom/cjs/react-dom-server.node.development.js +0.73% 399.93 kB 402.83 kB +0.55% 87.22 kB 87.70 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.development.js +0.72% 402.35 kB 405.25 kB +0.55% 88.36 kB 88.85 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.development.js +0.72% 402.76 kB 405.66 kB +0.55% 88.48 kB 88.96 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.development.js +0.71% 389.80 kB 392.58 kB +0.53% 85.63 kB 86.09 kB
oss-experimental/react-dom/umd/react-dom-server.browser.development.js +0.71% 421.56 kB 424.57 kB +0.45% 89.72 kB 90.13 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.70% 396.30 kB 399.08 kB +0.52% 87.63 kB 88.09 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.node.development.js +0.70% 398.15 kB 400.94 kB +0.52% 88.09 kB 88.55 kB
facebook-www/ReactDOMServerStreaming-dev.modern.js +0.70% 382.80 kB 385.47 kB +0.49% 84.23 kB 84.65 kB
oss-experimental/react-dom/umd/react-dom-server-legacy.browser.development.js +0.70% 415.21 kB 418.10 kB +0.50% 88.95 kB 89.39 kB
facebook-www/ReactDOMServer-dev.modern.js +0.69% 388.10 kB 390.78 kB +0.49% 85.50 kB 85.92 kB
oss-stable-semver/react-dom/cjs/react-dom-server.bun.development.js +0.69% 366.51 kB 369.02 kB +0.46% 80.69 kB 81.06 kB
oss-stable/react-dom/cjs/react-dom-server.bun.development.js +0.69% 366.53 kB 369.05 kB +0.46% 80.72 kB 81.09 kB
oss-stable-semver/react-dom/cjs/react-dom-server.browser.development.js +0.68% 369.27 kB 371.78 kB +0.45% 81.59 kB 81.96 kB
oss-stable/react-dom/cjs/react-dom-server.browser.development.js +0.68% 369.29 kB 371.80 kB +0.45% 81.61 kB 81.98 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.68% 369.34 kB 371.86 kB +0.46% 81.15 kB 81.53 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.68% 369.37 kB 371.88 kB +0.46% 81.18 kB 81.55 kB
oss-stable-semver/react-dom/cjs/react-dom-server.edge.development.js +0.68% 369.68 kB 372.19 kB +0.47% 81.71 kB 82.09 kB
oss-stable/react-dom/cjs/react-dom-server.edge.development.js +0.68% 369.70 kB 372.21 kB +0.47% 81.73 kB 82.11 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node.development.js +0.68% 370.75 kB 373.27 kB +0.45% 81.63 kB 81.99 kB
oss-stable/react-dom/cjs/react-dom-server.node.development.js +0.68% 370.78 kB 373.29 kB +0.45% 81.65 kB 82.02 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.node.development.js +0.68% 371.20 kB 373.71 kB +0.46% 81.61 kB 81.99 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.node.development.js +0.68% 371.22 kB 373.74 kB +0.46% 81.63 kB 82.01 kB
facebook-www/ReactDOMServer-dev.classic.js +0.68% 395.53 kB 398.20 kB +0.48% 87.14 kB 87.56 kB
oss-stable-semver/react-dom/umd/react-dom-server.browser.development.js +0.67% 387.07 kB 389.67 kB +0.45% 82.52 kB 82.89 kB
oss-stable/react-dom/umd/react-dom-server.browser.development.js +0.67% 387.10 kB 389.70 kB +0.45% 82.55 kB 82.92 kB
oss-stable-semver/react-dom/umd/react-dom-server-legacy.browser.development.js +0.67% 387.16 kB 389.76 kB +0.46% 82.07 kB 82.44 kB
oss-stable/react-dom/umd/react-dom-server-legacy.browser.development.js +0.67% 387.19 kB 389.79 kB +0.46% 82.10 kB 82.47 kB

Generated by 🚫 dangerJS against c1bc974

We can't rely on workingMap.size because we're now adding the fallback
nodes eagerly to the map.
@sebmarkbage sebmarkbage merged commit bff6be8 into facebook:main Sep 25, 2023
36 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 25, 2023
This fixes so that you can postpone in a fallback. This postpones the
parent boundary. I track the fallbacks in a separate replay node so that
when we resume, we can replay the fallback itself and finish the
fallback and then possibly later the content. By doing this we also
ensure we don't complete the parent too early since now it has a render
task on it.

There is one case that this surfaces that isn't limited to
prerender/resume but also render/hydrateRoot. I left todos in the tests
for this.

If you postpone in a fallback, and suspend in the content but eventually
don't postpone in the content then we should be able to just skip
postponing since the content rendered and we no longer need the
fallback. This is a bit of a weird edge case though since fallbacks are
supposed to be very minimal.

This happens because in both cases the fallback starts rendering early
as soon as the content suspends. This also ensures that the parent
doesn't complete early by increasing the blocking tasks. Unfortunately,
the fallback will irreversibly postpone its parent boundary as soon as
it hits a postpone.

When you suspend, the same thing happens but we typically deal with this
by doing a "soft" abort on the fallback since we don't need it anymore
which unblocks the parent boundary. We can't do that with postpone right
now though since it's considered a terminal state.

I think I'll just leave this as is for now since it's an edge case but
it's an annoying exception in the model. Makes me feel I haven't quite
nailed it just yet.

DiffTrain build for [bff6be8](bff6be8)
kodiakhq bot pushed a commit to vercel/next.js that referenced this pull request Oct 3, 2023
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
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
This fixes so that you can postpone in a fallback. This postpones the
parent boundary. I track the fallbacks in a separate replay node so that
when we resume, we can replay the fallback itself and finish the
fallback and then possibly later the content. By doing this we also
ensure we don't complete the parent too early since now it has a render
task on it.

There is one case that this surfaces that isn't limited to
prerender/resume but also render/hydrateRoot. I left todos in the tests
for this.

If you postpone in a fallback, and suspend in the content but eventually
don't postpone in the content then we should be able to just skip
postponing since the content rendered and we no longer need the
fallback. This is a bit of a weird edge case though since fallbacks are
supposed to be very minimal.

This happens because in both cases the fallback starts rendering early
as soon as the content suspends. This also ensures that the parent
doesn't complete early by increasing the blocking tasks. Unfortunately,
the fallback will irreversibly postpone its parent boundary as soon as
it hits a postpone.

When you suspend, the same thing happens but we typically deal with this
by doing a "soft" abort on the fallback since we don't need it anymore
which unblocks the parent boundary. We can't do that with postpone right
now though since it's considered a terminal state.

I think I'll just leave this as is for now since it's an edge case but
it's an annoying exception in the model. Makes me feel I haven't quite
nailed it just yet.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
This fixes so that you can postpone in a fallback. This postpones the
parent boundary. I track the fallbacks in a separate replay node so that
when we resume, we can replay the fallback itself and finish the
fallback and then possibly later the content. By doing this we also
ensure we don't complete the parent too early since now it has a render
task on it.

There is one case that this surfaces that isn't limited to
prerender/resume but also render/hydrateRoot. I left todos in the tests
for this.

If you postpone in a fallback, and suspend in the content but eventually
don't postpone in the content then we should be able to just skip
postponing since the content rendered and we no longer need the
fallback. This is a bit of a weird edge case though since fallbacks are
supposed to be very minimal.

This happens because in both cases the fallback starts rendering early
as soon as the content suspends. This also ensures that the parent
doesn't complete early by increasing the blocking tasks. Unfortunately,
the fallback will irreversibly postpone its parent boundary as soon as
it hits a postpone.

When you suspend, the same thing happens but we typically deal with this
by doing a "soft" abort on the fallback since we don't need it anymore
which unblocks the parent boundary. We can't do that with postpone right
now though since it's considered a terminal state.

I think I'll just leave this as is for now since it's an edge case but
it's an annoying exception in the model. Makes me feel I haven't quite
nailed it just yet.

DiffTrain build for commit bff6be8.
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