-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React strict mode support for the useSSRSafeId
hook
#3963
Conversation
6ea3ff8
to
0038471
Compare
useId
hookuseSSRSafeId
hook
useSSRSafeId
hookuseSSRSafeId
hook
I'm a bit hesitant about adding a new |
Thank you for providing the alternative. I think #3980 is an ideal approach for React 16 and 17. Streaming rendering is not widely used at the moment, but in the future it would be nice to implement an option to switch to |
@ciffelia @devongovett I haven't fully wrapped my head around the code of this provider, but couldn't we do something like this, to check for if ("useId" in React) {
// Use `React.useId`
} else {
// Use React 17/16 fallback
} What's not super clear to me is how to reconcile that with this PR vs with #3980, but I'm just curious why we couldn't use the above to get React 18 support. |
Please see last paragraph of the description for #3980 |
I'm missing the connection to my comment, @snowystinger. I'm reading that as:
I'm just confused why we can't just check for the presence of (My bad if I misunderstood what you're referring to) |
No worries, I should've expanded on it. |
Ah, got it, thanks! I misunderstood that "know a way to do it" part. I'll mull it over and see if I have any suggestions. |
Supersedes #3637. Fixes #2231. Related to #779.
This pull request adds options to fix hydration errors in React strict mode caused by the
useSSRSafeId
hook. The idea for this fix was suggested in the discussion on #3637 (comment). I created this separate pull request because I rewrote most part of the code I wrote in in the previous pull request.In React 18, users should specify the
"useId"
mode and passReact.useId
to theSSRProvider
. TheuseSSRSafeId
hook will then useReact.useId
internally.On React 16 or 17, users should set the
strictMode
property toprocess.env.NODE_ENV !== 'production'
. Then theuseSSRSafeId
hook incrementsctx.current
twice on the server side to mimic the behavior of the strict mode on the client. This idea was suggested by @LucasUnplugged on #3637 (comment).✅ Pull Request Checklist:
📝 Test Instructions:
Run unit tests.
🧢 Your Project:
pixiv/charcoal