]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): handle edge case of style mismatch without style attribute
authorEvan You <yyx990803@gmail.com>
Mon, 6 May 2024 22:38:16 +0000 (15:38 -0700)
committerEvan You <yyx990803@gmail.com>
Mon, 6 May 2024 22:38:16 +0000 (15:38 -0700)
ref #10786

packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-core/src/hydration.ts

index e0277622c1335d59fd8a6674814614f05b83cfff..ec9613c95712682ab60e035435253181b8eb1425 100644 (file)
@@ -1527,6 +1527,13 @@ describe('SSR hydration', () => {
       expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
     })
 
+    test('style mismatch when no style attribute is present', () => {
+      mountWithHydration(`<div></div>`, () =>
+        h('div', { style: { color: 'red' } }),
+      )
+      expect(`Hydration style mismatch`).toHaveBeenWarnedTimes(1)
+    })
+
     test('style mismatch w/ v-show', () => {
       mountWithHydration(`<div style="color:red;display:none"></div>`, () =>
         withDirectives(createVNode('div', { style: 'color: red' }, ''), [
index a7832ac3d579297dbc51b6067cf62c91f166405c..dd3da56a6247a973085b1094b224b882ddc5d091 100644 (file)
@@ -727,8 +727,8 @@ function propHasMismatch(
 ): boolean {
   let mismatchType: string | undefined
   let mismatchKey: string | undefined
-  let actual: any
-  let expected: any
+  let actual: string | boolean | null | undefined
+  let expected: string | boolean | null | undefined
   if (key === 'class') {
     // classes might be in different order, but that doesn't affect cascade
     // so we just need to check if the class lists contain the same classes.
@@ -739,7 +739,7 @@ function propHasMismatch(
     }
   } else if (key === 'style') {
     // style might be in different order, but that doesn't affect cascade
-    actual = el.getAttribute('style')
+    actual = el.getAttribute('style') || ''
     expected = isString(clientValue)
       ? clientValue
       : stringifyStyle(normalizeStyle(clientValue))