Closed felix-d closed 3 years ago
I'm interested in fixing this!
Regarding your suggestions, @felix-d:
this.props
.Here's two similar ways of solving this:
I'd be interested in implementing the style-hash ID approach. Am I missing another way? Thoughts, @felix-d and @nikgraf?
@mcbryant
An "id" prop would absolutely solve this issue! It would be a bit painful to require an "id" (or similar) prop for every component when you want server side rendering, though.
This is what Material UI does AFAIK.
The hashing solution seems like a good idea but it's more complex. I'd go with the id
solution first to fix the issue, and then maybe think about an alternative solution that involves hashing, but the id
solution is quite viable and solid š Simple is always better than complex š
Good reasoning!
For example, in
TextField
https://github.com/nikgraf/belle/blob/master/src/components/TextInput.js#L139 This breaks server side rendering because a new id is generated on the client.
warning.js:45Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server: (client) to;" class="style-idb6de" id="username" (server) to;" class="style-idd07b" id="username"
I guess you could use
key
orid
from props to create that id and fallback on a random id.