Skip to content

Commit

Permalink
fix(hydration): skip prop mismatch check for directives that mutate D…
Browse files Browse the repository at this point in the history
…OM in created

close #11189
  • Loading branch information
yyx990803 committed Jun 22, 2024
1 parent 7ad67ce commit 3169c91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import {
type ObjectDirective,
Suspense,
Teleport,
Transition,
Expand Down Expand Up @@ -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()
})
})
})
3 changes: 3 additions & 0 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3169c91

Please sign in to comment.