Skip to content
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

[Id] SSR – Mismatched server / client ids when running in StrictMode #811

Closed
andy-hook opened this issue Aug 2, 2021 · 29 comments · Fixed by #1006
Closed

[Id] SSR – Mismatched server / client ids when running in StrictMode #811

andy-hook opened this issue Aug 2, 2021 · 29 comments · Fixed by #1006
Labels
Type: Bug Confirmed bug

Comments

@andy-hook
Copy link
Collaborator

andy-hook commented Aug 2, 2021

Related #793

Original report via Discord:

I'm trying to create a Dialog with IdProvider and I can't understand why SSR doesn't work, I got an error:
Prop aria-controls did not match. Server: "radix-id-0-1" Client: "radix-id-0-4"

https://codesandbox.io/s/radixui-idprovider-ssr-mismatch-i3o1x

This is reproducible in our current SSR testing app since StrictMode was added in #795

Wrapping React.StrictMode or setting reactStrictMode: true in next.config is equivalent afaik.

@andy-hook andy-hook added the Type: Bug Confirmed bug label Aug 2, 2021
@andy-hook andy-hook changed the title [Id] Mismatched server / client ids when running in StrictMode [Id] Next.js – Mismatched server / client ids when running in StrictMode Aug 2, 2021
@andy-hook
Copy link
Collaborator Author

andy-hook commented Aug 6, 2021

Thought some more about this and then it struck me that of course this would be a problem, the implementation is proven non-deterministic in concurrent mode which is why StrictMode is having a cry about it and incrementing twice.

So then I thought about how might we solve for this and I kept ending up back in the same place – wouldn't it be easier to just not do this on the server in the first place? I did some digging and turns out Reach has been down this rabbit hole already and written a nice piece of documentation on it.

https://github.com/reach/reach-ui/blob/develop/packages/auto-id/src/index.tsx

While this is a warning and not a "today" problem, it will become a bigger issue in the future so the question is whether we'd want to take a similar approach here / now.

Worth noting that I did check in on other popular implementations and they suffer from the same issue.

@andy-hook andy-hook changed the title [Id] Next.js – Mismatched server / client ids when running in StrictMode [Id] SSR – Mismatched server / client ids when running in StrictMode Aug 6, 2021
@csantos1113
Copy link
Contributor

Any updates on this? We just ran into the same issue

@andy-hook
Copy link
Collaborator Author

Any updates on this?

Not since my follow up, one workaround is disabling StrictMode for now. The problem is only visible in development and production builds should behave as expected.

This issue isn't exclusive to Radix, it exists in many other id implementations in popular libraries. I need to speak with the team and see how we feel given the options available to us.

@csantos1113
Copy link
Contributor

This issue isn't exclusive to Radix, it exists in many other id implementations in popular libraries. I need to speak with the team and see how we feel given the options available to us.

Yeah, I created an issue in react-spectrum (adobe/react-spectrum#2231) for react-aria to see how they react and what ideas they might have as well.

Thanks for the quick response @andy-hook - and yes, I did exactly that 😅 strictMode disabled for now

@Clee681
Copy link

Clee681 commented Sep 29, 2021

Seeing the same issue as a NextJS user

@julianbenegas
Copy link

Any updates on this? It's a super annoying error 😅

@espired
Copy link

espired commented Oct 5, 2021

My logs gets filled up with this

@andy-hook
Copy link
Collaborator Author

andy-hook commented Oct 5, 2021

I agree that this warning is not ideal but our options to resolve it without compromise are limited. In order to deal with this today we’d likely need to render id’s on the client only, this has performance and a11y consequences.

Once stable our best bet will be useOpaqueIdentifier. For now disabling StrictMode remains the best workaround 🙏

@ashtonlance
Copy link

So I've disabled StrictMode in next.config.js and I'm still getting the error. Anyone else?

@andy-hook
Copy link
Collaborator Author

So I've disabled StrictMode in next.config.js and I'm still getting the error. Anyone else?

@ashtonlance Have you tried upgrading all of your radix-ui packages to latest?

@ashtonlance
Copy link

I have. Everything is up-to-date including Stitches.

These are the UI packages I'm using.

"@radix-ui/react-accordion": "^0.1.0",
"@radix-ui/react-dialog": "^0.1.0",
"@radix-ui/react-icons": "^1.0.3",
"@radix-ui/react-id": "^0.1.0",
"@radix-ui/react-progress": "^0.1.0",

@andy-hook
Copy link
Collaborator Author

Strange 🤔 my only other suggestion is to try nuking node_modules and pinning all of the primitive packages at @0.1.1, we know of an issue where different versions between packages and react-id don't play nicely at the moment.

@ashtonlance
Copy link

@andy-hook tried that and still getting the same console errors.

@andy-hook
Copy link
Collaborator Author

@ashtonlance sorry to hear this, I can't reproduce on my end. Do you have a public project I could take a look at?

@ashtonlance
Copy link

@andy-hook I have a vercel staging url I can share! unless you need the source code -- that repo is private but I could add you as a user.

@woshixixi
Copy link

same issue here, bug with tooltip component

@andy-hook
Copy link
Collaborator Author

@andy-hook I have a vercel staging url I can share! unless you need the source code -- that repo is private but I could add you as a user.

@ashtonlance If you could add me that'd be great.

@albingroen
Copy link

Same issue for me, and I'm using the Dialog components.

@ashtonlance
Copy link

@andy-hook I have a vercel staging url I can share! unless you need the source code -- that repo is private but I could add you as a user.

@ashtonlance If you could add me that'd be great.

Added. Thanks for taking a look!

@coderinblack08
Copy link

Possible react-18 solution?
reactwg/react-18#111

@jjenzz
Copy link
Contributor

jjenzz commented Nov 17, 2021

@coderinblack08 Yep, that is the renamed useOpaqueIdentifier hook we mentioned. Looking forward to giving it a spin 💃

@ajrussellaudio
Copy link

For anyone late to the party dropping in from Google, not able to upgrade to React 18 yet, suppressHydrationWarning (docs) on the JSX element causing the warning worked for me.

@jjenzz
Copy link
Contributor

jjenzz commented Jan 13, 2022

@ajrussellaudio If you are able to upgrade to the latest versions of the primitives, the IdProvider is no longer needed and these warnings should all go away regardless of what React version you are on.

@ajrussellaudio
Copy link

Awesome @jjenzz thanks!

@daniellizik
Copy link

@ajrussellaudio how are you able to determine which elements require the suppresshydrationwarning flag? My terminal just spits out this message a bunch of times without any reference to where it originates from. i'm on react@17.0.2 and @radix/react-id@0.1.6

@ajrussellaudio
Copy link

@daniellizik By manual process of elimination, commenting out components until the error disappears and following the tree down.

But as @jjenzz points out, this fix is no longer needed if you upgrade your radix primitives dependency.

@DennieMello
Copy link

Problem reappeared, using react: 18.2.0, next: 13.4.12 with app router, @radix-ui/react-dialog.

Error: app-index.js:31 Warning: Prop aria-controls did not match. Server: "radix-:R16qcq:" Client: "radix-:R4r9j9:"

Any ideas for a fix besides setting a custom value in aria-controls?

@joaom00
Copy link
Contributor

joaom00 commented Aug 8, 2023

@DennieMello Can you check if this is an issue on the Next.js side? #1684 (comment)

@DennieMello
Copy link

@DennieMello Can you check if this is an issue on the Next.js side? #1684 (comment)

Thanks, fixed in next: "13.4.13".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.