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

fix(engine-core): dynamic class with empty string results in hydration mismatch #4684

Merged
merged 5 commits into from
Oct 25, 2024

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Oct 22, 2024

Details

Hopefully this is right, but if not there should be some test that fails.

Closes #4661

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🔬 Yes, it does include an observable change.

No hydration mismatch on dynamic class with empty string 😄

GUS work item

@@ -664,7 +664,7 @@ function validateClassAttr(

const elmClassName = getAttribute(elm, 'class');

if (!isUndefined(className) && String(className) !== elmClassName) {
if (!isUndefined(className) && String(className) !== elmClassName && className !== '') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't totally right. If the client class name is '' but the server class name is 'foo' then there will be no mismatch when there should be.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See: #4698

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I figured some case wasn't covered here.

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see above

@cardoso
Copy link
Contributor Author

cardoso commented Oct 24, 2024

Thanks @nolanlawson . Should I try fixing this once you merge the new tests? Or are you taking care of it as well?

@nolanlawson
Copy link
Collaborator

@cardoso Feel free to go ahead! If you don't get to it, I'll get to it eventually. 🙂

Copy link
Contributor Author

@cardoso cardoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the logic, tests are passing @nolanlawson .

Comment on lines 667 to 672
if (!isUndefined(className) && String(className) !== elmClassName) {
if (
!isUndefined(className) &&
String(className) !== elmClassName &&
// No mismatch if SSR className is empty and the client-side class is null
!(className === '' && isNull(elmClassName))
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if is starting to get hairy, but the auto-formatting gave me the idea of adding this comment. I think this is OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be (className !== '' || !isNull(elmClassName)) but I found this way more readable and easy to explain via the comment.

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you. 🙇

@nolanlawson
Copy link
Collaborator

/nucleus test

@nolanlawson nolanlawson enabled auto-merge (squash) October 25, 2024 19:59
@nolanlawson
Copy link
Collaborator

/nucleus test

@nolanlawson nolanlawson merged commit fa6ef21 into salesforce:master Oct 25, 2024
14 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic class with empty string results in hydration mismatch
2 participants