]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): skip prop mismatch check for directives that mutate DOM in created
authorEvan You <evan@vuejs.org>
Sat, 22 Jun 2024 10:05:45 +0000 (18:05 +0800)
committerEvan You <evan@vuejs.org>
Sat, 22 Jun 2024 10:05:45 +0000 (18:05 +0800)
close #11189

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

index f68d2f240d4f3a46b120e602e0445c3396f926c5..53974bc93843f65e4442d3e98bf619fec0485f71 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 import {
+  type ObjectDirective,
   Suspense,
   Teleport,
   Transition,
@@ -1695,5 +1696,24 @@ describe('SSR hydration', () => {
       app.mount(container)
       expect(`Hydration style mismatch`).not.toHaveBeenWarned()
     })
+
+    // #11189
+    test('should not warn for directives that mutate DOM in created', () => {
+      const container = document.createElement('div')
+      container.innerHTML = `<div class="test red"></div>`
+      const vColor: ObjectDirective = {
+        created(el, binding) {
+          el.classList.add(binding.value)
+        },
+      }
+      const app = createSSRApp({
+        setup() {
+          return () =>
+            withDirectives(h('div', { class: 'test' }), [[vColor, 'red']])
+        },
+      })
+      app.mount(container)
+      expect(`Hydration style mismatch`).not.toHaveBeenWarned()
+    })
   })
 })
index ec829a6e3ba2581ceef568dd48fbc6303c0c13d0..9376604b16fa0c759c42b7ef54d6c7093e83e83a 100644 (file)
@@ -459,6 +459,9 @@ export function createHydrationFunctions(
             // check hydration mismatch
             if (
               (__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
+              // #11189 skip if this node has directives that have created hooks
+              // as it could have mutated the DOM in any possible way
+              !(dirs && dirs.some(d => d.dir.created)) &&
               propHasMismatch(el, key, props[key], vnode, parentComponent)
             ) {
               logMismatchError()