Skip to content

fix: resolve React useId SSR hydration mismatch#8433

Merged
GiveMe-A-Name merged 3 commits intomainfrom
fix/react-useid-ssr-hydration
Mar 12, 2026
Merged

fix: resolve React useId SSR hydration mismatch#8433
GiveMe-A-Name merged 3 commits intomainfrom
fix/react-useid-ssr-hydration

Conversation

@GiveMe-A-Name
Copy link
Member

@GiveMe-A-Name GiveMe-A-Name commented Mar 10, 2026

Summary

This PR fixes a hydration mismatch issue when using React's useId hook in SSR mode. The fix ensures consistent ID generation between server and client by introducing a new useId configuration option in the Modern.js runtime, allowing users to specify a unique identifier to prevent ID conflicts during hydration. Includes integration tests for SSR useId scenarios.

- Add SSR_HYDRATION_ID_PREFIX constant in @modern-js/utils
- Pass identifierPrefix to renderToString (string SSR)
- Pass identifierPrefix to renderToPipeableStream (stream SSR Node.js)
- Pass identifierPrefix to renderToReadableStream (stream SSR Edge)
- Pass identifierPrefix to hydrateRoot (client hydration)
- Add integration test for useId SSR hydration

Closes #8363
@netlify
Copy link

netlify bot commented Mar 10, 2026

Deploy Preview for modernjs-byted ready!

Name Link
🔨 Latest commit bbdcfce
🔍 Latest deploy log https://app.netlify.com/projects/modernjs-byted/deploys/69afd3927a29e90008bbe5fd
😎 Deploy Preview https://deploy-preview-8433--modernjs-byted.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 95 (🔴 down 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

🦋 Changeset detected

Latest commit: bbdcfce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 113 packages
Name Type
@modern-js/runtime Patch
@modern-js/render Patch
@modern-js/utils Patch
@modern-js/plugin-bff Patch
@modern-js/plugin-styled-components Patch
@modern-js/plugin-i18n Patch
@integration-test/alias-set Patch
app-document Patch
async-entry-test Patch
tmp Patch
bff-api-app Patch
bff-client-app Patch
bff-indep-client-app Patch
bff-hono Patch
integration-clean-dist-path Patch
integration-compatibility Patch
integration-custom-dist-path Patch
custom-file-system-entry Patch
integration-custom-template Patch
deploy Patch
deploy-server Patch
dev-server Patch
integration-disable-html Patch
app-custom-entries Patch
app-custom-routes-runtime Patch
app-custom Patch
app-entry Patch
app-route Patch
app-entry-server Patch
i18n-app-csr-html-lang Patch
i18n-app Patch
i18n-app-ssr-html-lang Patch
i18n-app-ssr Patch
i18n-custom-i18n-wrapper Patch
i18n-mf-app-provider Patch
i18n-mf-component-provider Patch
i18n-mf-consumer Patch
i18n-routes Patch
i18n-routes-ssr Patch
@integration-test/image-component Patch
main-entry-name Patch
nonce Patch
pure-esm-project Patch
routes-match Patch
routes Patch
app-rsbuild-hooks Patch
rsc-csr-app Patch
rsc-csr-routes Patch
rsc-ssr-app Patch
rsc-ssr-routes Patch
basic-app-rstest-browser Patch
basic-app-rstest Patch
runtime-custom-plugin Patch
runtime-custom-config-plugin Patch
select-mul-entry-test Patch
select-one-entry-test Patch
server-config Patch
server-json-script Patch
server-monitors Patch
server-prod Patch
server-routes Patch
@source-code-build/app Patch
ssg-fixtures-mega-list-routes Patch
ssg-fixtures-nested-routes Patch
ssg-fixtures-simple Patch
ssg-fixtures-web-server Patch
ssr-base-async-entry-test Patch
ssr-base-json-test Patch
ssr-base-test Patch
ssr-base-fallback-test Patch
init Patch
ssr-base-loadable Patch
ssr-partial-test Patch
ssr-script-loading Patch
ssr-useid-test Patch
ssr-streaming-inline-test Patch
ssr-streaming-test Patch
styled-components-stream Patch
styled-components-string Patch
integration-tailwindcss-v2 Patch
integration-tailwindcss-v3 Patch
integration-tailwindcss-v4 Patch
tmp-dir Patch
write-to-dist Patch
@modern-js/bundle-diff-benchmark Patch
@modern-js/builder Patch
@modern-js/plugin-data-loader Patch
@modern-js/plugin-ssg Patch
@modern-js/bff-core Patch
@modern-js/server-core Patch
@modern-js/create-request Patch
@modern-js/plugin-polyfill Patch
@modern-js/prod-server Patch
@modern-js/server Patch
@modern-js/server-utils Patch
@modern-js/app-tools Patch
@modern-js/i18n-utils Patch
@modern-js/plugin Patch
@modern-js/runtime-utils Patch
@scripts/release-node Patch
@modern-js/server-runtime Patch
@modern-js/adapter-rstest Patch
@modern-js/image Patch
entries-app-builder Patch
@modern-js/create Patch
@modern-js/main-doc Patch
@modern-js/tsconfig Patch
@modern-js/bff-runtime Patch
@modern-js/sandpack-react Patch
@modern-js/types Patch
@modern-js/rslib Patch
@scripts/prebundle Patch
@scripts/rstest-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@GiveMe-A-Name GiveMe-A-Name changed the title Fix/react useid ssr hydration fix: resolve React useId SSR hydration mismatch Mar 10, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

Rsdoctor Bundle Diff Analysis

📊 Quick Summary
Project Total Size Change
bundle-diff 2.9 MB +353.0 B (0.0%)
📋 Detailed Reports (Click to expand)

📁 bundle-diff

Path: benchmark/bundle-diff/dist/rsdoctor-data.json

📌 Baseline Commit: 4c25918ff6 | PR: #8413

Metric Current Baseline Change
📊 Total Size 2.9 MB 2.9 MB +353.0 B (0.0%)
📄 JavaScript 498.1 KB 498.0 KB +59.0 B (0.0%)
🎨 CSS 1.2 KB 1.2 KB 0
🌐 HTML 5.9 KB 5.9 KB 0
📁 Other Assets 2.4 MB 2.4 MB +294.0 B (0.0%)

📦 Download Diff Report: bundle-diff Bundle Diff

Generated by Rsdoctor GitHub Action

@GiveMe-A-Name GiveMe-A-Name merged commit 65a06b3 into main Mar 12, 2026
10 checks passed
@GiveMe-A-Name GiveMe-A-Name deleted the fix/react-useid-ssr-hydration branch March 12, 2026 08:05
@caohuilin caohuilin mentioned this pull request Mar 18, 2026
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.

2 participants