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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/@lwc/engine-core/src/framework/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,12 @@ function validateClassAttr(

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

if (!isUndefined(className) && String(className) !== elmClassName) {
if (
!isUndefined(className) &&
String(className) !== elmClassName &&
// No mismatch if SSR `class` attribute is missing and CSR `class` is the empty string
!(className === '' && isNull(elmClassName))
) {
// className is used when class is bound to an expr.
nodesAreCompatible = false;
// stringify for pretty-printing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
props: {
classes: '',
},
snapshot(target) {
const p = target.shadowRoot.querySelector('p');
return {
p,
classes: p.className,
};
},
test(target, snapshots) {
const p = target.shadowRoot.querySelector('p');
expect(p).toBe(snapshots.p);
expect(p.className).toBe(snapshots.classes);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p class={classes}>text</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { LightningElement, api } from 'lwc';
export default class Main extends LightningElement {
@api classes;
}
Loading