Skip to content

Commit 3ecdf03

Browse files
yyx990803edison1105
authored andcommitted
fix(hydration): fix class and style hydration mismatch message
close vuejs#10067
1 parent 172d568 commit 3ecdf03

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

packages/runtime-core/src/hydration.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -725,29 +725,29 @@ function propHasMismatch(
725725
if (key === 'class') {
726726
// classes might be in different order, but that doesn't affect cascade
727727
// so we just need to check if the class lists contain the same classes.
728-
actual = toClassSet(el.getAttribute('class') || '')
729-
expected = toClassSet(normalizeClass(clientValue))
730-
if (!isSetEqual(actual, expected)) {
728+
actual = el.getAttribute('class')
729+
expected = normalizeClass(clientValue)
730+
if (!isSetEqual(toClassSet(actual || ''), toClassSet(expected))) {
731731
mismatchType = mismatchKey = `class`
732732
}
733733
} else if (key === 'style') {
734734
// style might be in different order, but that doesn't affect cascade
735-
actual = toStyleMap(el.getAttribute('style') || '')
736-
expected = toStyleMap(
737-
isString(clientValue)
738-
? clientValue
739-
: stringifyStyle(normalizeStyle(clientValue)),
740-
)
735+
actual = el.getAttribute('style')
736+
expected = isString(clientValue)
737+
? clientValue
738+
: stringifyStyle(normalizeStyle(clientValue))
739+
const actualMap = toStyleMap(actual)
740+
const expectedMap = toStyleMap(expected)
741741
// If `v-show=false`, `display: 'none'` should be added to expected
742742
if (vnode.dirs) {
743743
for (const { dir, value } of vnode.dirs) {
744744
// @ts-expect-error only vShow has this internal name
745745
if (dir.name === 'show' && !value) {
746-
expected.set('display', 'none')
746+
expectedMap.set('display', 'none')
747747
}
748748
}
749749
}
750-
if (!isMapEqual(actual, expected)) {
750+
if (!isMapEqual(actualMap, expectedMap)) {
751751
mismatchType = mismatchKey = 'style'
752752
}
753753
} else if (

0 commit comments

Comments
 (0)