Skip to content

feat: automatically use React DOM browser for Suspense SSR - #4330

Draft
huozhi wants to merge 2 commits into
mainfrom
feat/suspense-browser-opt-in
Draft

feat: automatically use React DOM browser for Suspense SSR#4330
huozhi wants to merge 2 commits into
mainfrom
feat/suspense-browser-opt-in

Conversation

@huozhi

@huozhi huozhi commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

When useSWR suspends during SSR without data, SWR currently throws “Fallback data is required when using Suspense in SSR.” This change detects React DOM's Canary browser API and calls React.use(browser()) when available, allowing React to render the nearest Suspense fallback and fetch the data in the browser automatically.

No new configuration is required. Existing fallback/preloaded data continues to render on the server, and older runtimes retain the existing error. This also covers useSWRInfinite through the shared core hook. React DOM is an optional peer, with a React Native mapping that excludes it in Metro.

The E2E app uses Next.js 16.4.0-canary.19, which bundles React DOM 19.3.0-canary-f4e439e1-20260902 with the API.

Validation:

  • SWR build and production Next.js build passed.
  • Type checks, typing tests, lint, and formatting passed.
  • 21 targeted SSR/Suspense unit tests and 3 browser tests passed.
  • Browser coverage verifies server fallbacks with JavaScript disabled, client hydration without console errors, infinite queries, supplied data, and disabled keys.
  • Metro resolver checks map React DOM to an empty module on iOS and Android.

React API reference: https://react.dev/reference/react-dom/browser

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​next@​16.3.0-canary.97 ⏵ 16.4.0-canary.1962 +11100 +7590 +129970

View full report

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant