From: Evan You Date: Sat, 22 Jun 2024 10:05:45 +0000 (+0800) Subject: fix(hydration): skip prop mismatch check for directives that mutate DOM in created X-Git-Tag: v3.4.30~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3169c914939d02a013b2938aff30dac8525923f8;p=thirdparty%2Fvuejs%2Fcore.git fix(hydration): skip prop mismatch check for directives that mutate DOM in created close #11189 --- diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index f68d2f240d..53974bc938 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -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 = `
` + 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() + }) }) }) diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index ec829a6e3b..9376604b16 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -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()