Skip to content

fix(runtime-dom): fix multi vShow impact each other #10344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/runtime-core/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export type DirectiveHook<T = any, Prev = VNode<any, T> | null, V = any> = (
binding: DirectiveBinding<V>,
vnode: VNode<any, T>,
prevVNode: Prev,
// register a callback witch will be called
// after all dirHooks have been executed
postFlushDirs?: (fn: () => void) => void,
) => void

export type SSRDirectiveHook = (
Expand Down Expand Up @@ -129,6 +132,7 @@ export function invokeDirectiveHook(
) {
const bindings = vnode.dirs!
const oldBindings = prevVNode && prevVNode.dirs!
const postFlushDirsQueue: (() => void)[] = []
for (let i = 0; i < bindings.length; i++) {
const binding = bindings[i]
if (oldBindings) {
Expand All @@ -147,8 +151,13 @@ export function invokeDirectiveHook(
binding,
vnode,
prevVNode,
(fn: () => void) => {
postFlushDirsQueue.push(fn)
},
])
resetTracking()
}
}
postFlushDirsQueue.forEach(postDir => postDir())
postFlushDirsQueue.length = 0
}
19 changes: 13 additions & 6 deletions packages/runtime-dom/src/directives/vShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,31 @@ export const vShow: ObjectDirective<VShowElement> & { name?: 'show' } = {
transition.enter(el)
}
},
updated(el, { value, oldValue }, { transition }) {
updated(el, { value, oldValue }, { transition }, _, postFlush) {
if (
!value === !oldValue &&
(el.style.display === el[vShowOriginalDisplay] || !value)
(el.style.display === el[vShowOriginalDisplay] || (!value && transition))
)
return
if (transition) {
if (value) {
transition.beforeEnter(el)
setDisplay(el, true)
transition.enter(el)
postFlush!(() => {
transition.beforeEnter(el)
setDisplay(el, true)
transition.enter(el)
})
} else {
transition.leave(el, () => {
setDisplay(el, false)
})
}
} else {
setDisplay(el, value)
// #10038
// when multi vShow be applied to the same element
// and the sync setDisplay will impact other vShow
postFlush!(() => {
setDisplay(el, value)
})
}
},
beforeUnmount(el, { value }) {
Expand Down