Repository navigation
Keep the server fallback when a client-rendered boundary suspends during hydration - #38174
transmogrify-cell wants to merge 3 commits into
Conversation
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.
|
Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
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 @michaltarasiuk tagging you too in case you want to check the test matches what you're seeing in your repro. |
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.
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.
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:
<!--$!-->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.keptServerFallbackflag on the dehydrated state stops it from being reported again on retry.Nothing changes for boundaries that aren't client-rendered fallbacks, or when the client render doesn't suspend.
Known limitations
@gate FIXMEwith a comment explaining this.How did you test this change?
Removed
@gate FIXMEfrom the tests that now pass:browser()test added earlier in this PRTheir 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 ofLoading (dark)).yarn test packages/react-dom packages/react-reconciler: all 227 suites pass in dev. With--prod, everything passes except oneReactTransition-testcase. It doesn't involve hydration and passed 3 of 3 runs on its own.ReactDOMFizzServer,ReactDOMServerPartialHydration,ReactDOMServerSelectiveHydration,ReactDOMFizzShellHydrationandReactDOMFloatpass 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,eslintandprettierpass.