You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using useId or useSSRSafeId with SSRProvider, Next.js and React Strict Mode, IDs are not generated consistently. In Strict Mode, React deliberately double invoke render, useMemo, etc to detect unexpected side effects logging any errors to the browser console.
🤔 Expected Behavior
Generated IDs should be deterministic. Console should not log any errors.
😯 Current Behavior
Browser logs error with something like
Warning: Prop `id` did not match. Server: "react-aria-1" Client: "react-aria-2"
(Note the off-by-one error).
💁 Possible Reason for bug
It appears that this is due to incrementing the counter inside useMemo, a side-effect which React does not permit:
Remember that the function passed to useMemo runs during rendering. Don’t do anything there that you wouldn’t normally do while rendering. For example, side effects belong in useEffect, not useMemo.
...
You may rely on useMemo as a performance optimization, not as a semantic guarantee. In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components.
🐛 Bug Report
When using
useId
oruseSSRSafeId
withSSRProvider
, Next.js and React Strict Mode, IDs are not generated consistently. In Strict Mode, React deliberately double invoke render,useMemo
, etc to detect unexpected side effects logging any errors to the browser console.🤔 Expected Behavior
Generated IDs should be deterministic. Console should not log any errors.
😯 Current Behavior
Browser logs error with something like
(Note the off-by-one error).
💁 Possible Reason for bug
It appears that this is due to incrementing the counter inside
useMemo
, a side-effect which React does not permit:🔦 Context
This is a transitive dependency of React Bootstrap 2.0.0-rc.0. See react-bootstrap/react-bootstrap#6084
💻 Code Sample
A minimal live example is on CodeSandbox here
pages/index.tsx
:next.config.js
:🌍 Your Environment
The text was updated successfully, but these errors were encountered: