dillon1000/react
Commit
Browse files [Fix] properly track `useId` use in StrictMode in development (#25713)
In `<StrictMode>` in dev hooks are run twice on each render. For `useId` the re-render pass uses the `updateId` implementation rather than `mountId`. In the update path we don't increment the local id counter. This causes the render to look like no id was used which changes the tree context and leads to a different set of IDs being generated for subsequent calls to `useId` in the subtree. This was discovered here: https://github.com/vercel/next.js/issues/43033 It was causing a hydration error because the ID generation no longer matched between server and client. When strict mode is off this does not happen because the hooks are only run once during hydration and it properly sees that the component did generate an ID. The fix is to not reset the localIdCounter in `renderWithHooksAgain`. It gets reset anyway once the `renderWithHooks` is complete and since we do not re-mount the ID in the `...Again` pass we should retain the state from the initial pass.
Changed paths3 files
First-parent comparisonpackages/react-dom/src/__tests__/ReactDOMUseId-test.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.new.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.old.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…