Skip to content

Commit 3169c91

Browse files
committed
fix(hydration): skip prop mismatch check for directives that mutate DOM in created
close #11189
1 parent 7ad67ce commit 3169c91

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import {
6+
type ObjectDirective,
67
Suspense,
78
Teleport,
89
Transition,
@@ -1695,5 +1696,24 @@ describe('SSR hydration', () => {
16951696
app.mount(container)
16961697
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
16971698
})
1699+
1700+
// #11189
1701+
test('should not warn for directives that mutate DOM in created', () => {
1702+
const container = document.createElement('div')
1703+
container.innerHTML = `<div class="test red"></div>`
1704+
const vColor: ObjectDirective = {
1705+
created(el, binding) {
1706+
el.classList.add(binding.value)
1707+
},
1708+
}
1709+
const app = createSSRApp({
1710+
setup() {
1711+
return () =>
1712+
withDirectives(h('div', { class: 'test' }), [[vColor, 'red']])
1713+
},
1714+
})
1715+
app.mount(container)
1716+
expect(`Hydration style mismatch`).not.toHaveBeenWarned()
1717+
})
16981718
})
16991719
})

packages/runtime-core/src/hydration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ export function createHydrationFunctions(
459459
// check hydration mismatch
460460
if (
461461
(__DEV__ || __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__) &&
462+
// #11189 skip if this node has directives that have created hooks
463+
// as it could have mutated the DOM in any possible way
464+
!(dirs && dirs.some(d => d.dir.created)) &&
462465
propHasMismatch(el, key, props[key], vnode, parentComponent)
463466
) {
464467
logMismatchError()

0 commit comments

Comments
 (0)