Skip to content

Keep the server fallback when a client-rendered boundary suspends during hydration - #38174

Open
transmogrify-cell wants to merge 3 commits into
react:mainfrom
transmogrify-cell:test/browser-fallback-hydration-37620
Open

transmogrify-cell wants to merge 3 commits into
react:mainfrom
transmogrify-cell:test/browser-fallback-hydration-37620

Conversation

@transmogrify-cell

@transmogrify-cell transmogrify-cell commented Nov 9, 2026 •

Copy link
Copy Markdown

Summary

Fixes #37620.

When the server leaves a boundary in its fallback state (browser(), abort(), or a server error) and the client render then suspends, React deletes the server fallback and mounts an identical one, which restarts CSS animations. #24236 fixed this in 2022 by holding the render, and #24434 reverted it after a late-mutations regression at Meta. Its tests stayed here as @gate FIXME.

This PR handles it inside the boundary, without changing when the root commits:

  • If the client render of a <!--$!--> boundary suspends on data and the boundary hasn't received new props or a context change, it stays dehydrated and keeps the server fallback, like a still-streaming boundary does. Once the data resolves, the boundary retries at a normal retry lane.
  • The "switched to client rendering" error is still reported in that commit, as it is today. A keptServerFallback flag on the dehydrated state stops it from being reported again on retry.
  • A dehydrated boundary normally bails out without checking context. When the server fallback has been kept, it now checks for context changes on bailout, so the fallback is rerendered when a context it reads changes.
  • If the boundary gets new props or a context change while suspended, or suspends on a stylesheet (which only retries after a fallback commits), it recreates the fallback exactly as it does today.

Nothing changes for boundaries that aren't client-rendered fallbacks, or when the client render doesn't suspend.

Known limitations

How did you test this change?

  • Removed @gate FIXME from the tests that now pass:

    Their expectations were updated for two things that changed since 2022: the current DEV/prod error messages, and the 300ms retry reveal throttle (jest.runAllTimers()). The server error is now expected at hydration time, matching current behavior, rather than after the content resolves.

  • Added a test that changes a context the kept fallback reads, without changing the boundary's props. It fails without the bailout change (Loading (light) instead of Loading (dark)).

  • yarn test packages/react-dom packages/react-reconciler: all 227 suites pass in dev. With --prod, everything passes except one ReactTransition-test case. It doesn't involve hydration and passed 3 of 3 runs on its own.

  • ReactDOMFizzServer, ReactDOMServerPartialHydration, ReactDOMServerSelectiveHydration, ReactDOMFizzShellHydration and ReactDOMFloat pass with -r=stable, -r=stable --prod, -r=www-classic (both variants), and -r=www-modern (variant false, and variant true --prod).

  • yarn flow dom-node, eslint and prettier pass.

When a boundary is left in its fallback state by browser() and the client
retry suspends, React deletes the server fallback and mounts a new one,
restarting CSS animations (react#37620). This is the same behavior the existing
`@gate FIXME` tests cover for server errors, which were disabled when react#24236
was reverted in react#24434.

Add a `@gate FIXME` test for the browser() case, and a passing test that
fallback prop updates still render while the client retry is suspended, so a
fix that keeps the server fallback doesn't leave it stale.
@meta-cla

meta-cla Bot commented Nov 9, 2026

Copy link
Copy Markdown

Hi @transmogrify-cell!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

A size report will appear here when the build finishes.

Generated by sizebot against a4f2462

@meta-cla

meta-cla Bot commented Nov 9, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@transmogrify-cell

transmogrify-cell commented Nov 10, 2026 •

Copy link
Copy Markdown
Author

Hey @meta-cla @github-actions @gnoff @eps1lon, would one of you mind taking a look at this when you get a chance? It's just tests, no fix. One is a @gate FIXME for the fallback getting recreated after browser() (same as the existing server error ones), and the other checks that new fallback props still show up while it's suspended, since both open PRs for #37620 break that.

@michaltarasiuk tagging you too in case you want to check the test matches what you're seeing in your repro.

@transmogrify-cell transmogrify-cell changed the title Add tests for fallback reuse when hydration suspends after browser() Keep the server fallback when a client-rendered boundary suspends during hydration Nov 10, 2026
When the server leaves a boundary in its fallback state (browser(), abort,
or a server error) and the client render suspends on data, React deleted
the server fallback and mounted an identical one, restarting CSS
animations (react#37620).

If the boundary hasn't received new props or a context change, it now
stays dehydrated and keeps the server fallback until the data resolves,
then retries at a normal retry lane. This is scoped to the boundary and
doesn't change when the root commits, unlike react#24236. The server error is
still reported in the same commit as before, and a keptServerFallback
flag prevents reporting it again on retry. A kept boundary checks for
context changes when it bails out, so the fallback still updates when a
context it reads changes. Updates with new props and suspensey resources
recreate the fallback as before.

Re-enable the react#24236 tests that now pass, updated for current error
messages and retry throttling. The transition test stays gated: we don't
hold transitions to keep the server fallback.
ZyeL13 added a commit to ZyeL13/react that referenced this pull request Nov 25, 2026
On top of react#38174's keptServerFallback machinery, scope the 2nd-pass
keep-condition to the fallback itself (isSameFallback: same type/key
and shallow-equal props, ref compared via props since element.ref
warns in React 19) instead of the whole boundary (!didReceiveUpdate),
and propagate parent context changes unconditionally in the first pass
so a context change affecting the fallback is still visible via
childLanes. This un-gates the transition FIXME test (3/3 vs react#38174's
2/3) and adds a regression test for a combined primary-children +
context change while suspended.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Suspense fallback remounts on hydration after use(browser()) + client use(promise)

2 participants