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
fix(styled): Ensure no hydration mismatch with React.useId #2542
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
862729d
Current behavior for useId
eps1lon 2d79250
fix(styled): Ensure no hydration mismatch with React.useId
eps1lon 865ff4a
yarn changeset
eps1lon 7589dda
Update snapshots
eps1lon a3fb719
Dirty fix for enzyme matchers
eps1lon e98ebd8
Fragment -> Noop
eps1lon aac6191
Apply same pattern to class-names and emotion-element
eps1lon 77888db
tweak fragment unwrapping in `@emotion/jest`
Andarist 8c3d765
Fixed enzyme-related serialization tests
Andarist d56c781
Fix more cases and add new tests
Andarist 298afaa
add tests for avoiding id mismatches when using css prop and ClassNam…
Andarist 60d992e
Fix flow errors
Andarist 76ddec5
Reset html before each rehydration test
Andarist d386c78
tweak changesets
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emotion/styled': patch | ||
--- | ||
|
||
Fix hydration mismatches if `React.useId` is used | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder - would you be open to creating a PR targeting this PR that would add tests for this (this would require bumping React version)? I would love to have a way to verify changes like this but I'm also hesitant to land React 18 on our main branch before it hits its stable mark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A robust hydration test suite is pretty involved since you really need two separated processes: one for SSR and one for hydrating.
The linked codesandbox in the issue description should be sufficient for manual verification. It has a hydration mismatch with the latest version on npm but none with the codesandbox build from this PR:
Broken with
@emotion/styled@11.3.0
: https://codesandbox.io/s/sad-breeze-qznnl?file=/src/Sidebar.jsFixed with this PR: https://codesandbox.io/s/serene-platform-r4eyr?file=/src/Sidebar.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ye, I'm not for something like that now. It's possible to just mock whatever
isBrowser
checks before server and client renders to get a good representation of the real situation. For example this PR has introduced such tests here (IIRC)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for the pointers. Will look into it.
I can install it behind an alias and let jest use it for specific tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that would be cool - I have never used aliases like this. Hopefully, this won't be too problematic ;p Having that in place would be awesome ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test illustrating the behavior without this change:
862729d
(#2542)