Skip to content

Preserve painted SSR Suspense fallback DOM on client re-suspend (Fixes #37620) - #38005

Open
gamgsp wants to merge 1 commit into
react:mainfrom
gamgsp:fix/suspense-fallback-hydration-remount
Open

gamgsp wants to merge 1 commit into
react:mainfrom
gamgsp:fix/suspense-fallback-hydration-remount

Conversation

@gamgsp

@gamgsp gamgsp commented Oct 27, 2026

Copy link
Copy Markdown

Fixes #37620

Summary

Preserves the painted SSR Suspense fallback DOM nodes when client hydration suspends again on a client-created promise (e.g. use(browser()) followed by Web APIs like localStorage, IndexedDB, or client timers).

Background

On full page load with React 19 / Fizz, when a component triggers a recoverable browser bailout, Fizz flushes the painted <Suspense> fallback into HTML.
During client hydration, when the component re-suspends on a client-only promise, React previously entered mountSuspenseFallbackAfterRetryWithoutHydrating, deleting the server-rendered fallback and mounting an identical client fallback. This drops existing DOM state and abruptly restarts CSS animations (such as progress bars and skeleton loaders).

Solution

  1. Preserve DehydratedFragment:
    • In updateDehydratedSuspenseComponent, when a boundary has a recoverable digest (REACT_RECOVERABLE_DIGEST) and a valid DehydratedFragment, remove the fragment from workInProgress.deletions instead of queuing it for deletion.
    • Wire the preserved DehydratedFragment as the sibling of the hidden offscreen primary child.
  2. Prevent Redundant Re-render:
    • In updateSuspenseFallbackChildren and updateSuspenseComponent, handle fallbackChildFragment.tag === DehydratedFragment so the live DOM is left intact without re-invoking or cloning fallback children.
  3. Offscreen State:
    • Maintain the primary children inside a hidden offscreen fiber until client promises resolve.

Testing

  • Added regression tests to packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js validating:
    • Fallback DOM nodes (span) stay strictly identical across client hydration.
    • Multi-step client promise chains remain on the same painted fallback without remounting.
    • Standard error boundary fallback paths remain unaffected.

@meta-cla

meta-cla Bot commented Oct 27, 2026

Copy link
Copy Markdown

Hi @gamgsp!

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 Oct 27, 2026 •

Copy link
Copy Markdown

The build for this commit did not complete, so there is no size report. See the workflow run for details.

Generated by sizebot against 9841e22

@meta-cla meta-cla Bot added the CLA Signed label Nov 7, 2026
@meta-cla

meta-cla Bot commented Nov 7, 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!

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)

1 participant