Skip to content
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

fix(runtime-core): cleanup hoisted vnode when unmount component #9219

Closed
wants to merge 8 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
7 changes: 7 additions & 0 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ export interface ComponentInternalInstance {
*/
ut?: (vars?: Record<string, string>) => void

/**
* hoisted vnodes
* @internal
*/
hoistedVNodes?: VNode[] | null

/**
* dev only. For style v-bind hydration mismatch checks
* @internal
Expand Down Expand Up @@ -567,6 +573,7 @@ export function createComponentInstance(
provides: parent ? parent.provides : Object.create(appContext.provides),
accessCache: null!,
renderCache: [],
hoistedVNodes: null,

// local resolved assets
components: null,
Expand Down
12 changes: 11 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ function baseCreateRenderer(
) => {
let el: RendererElement
let vnodeHook: VNodeHook | undefined | null
const { props, shapeFlag, transition, dirs } = vnode
const { props, shapeFlag, patchFlag, transition, dirs } = vnode

el = vnode.el = hostCreateElement(
vnode.type as string,
Expand All @@ -638,6 +638,12 @@ function baseCreateRenderer(
props,
)

if (patchFlag === PatchFlags.HOISTED && parentComponent) {
;(
parentComponent.hoistedVNodes || (parentComponent.hoistedVNodes = [])
).push(vnode)
}

// mount children first, since some props may rely on child content
// being already rendered, e.g. `<select value>`
if (shapeFlag & ShapeFlags.TEXT_CHILDREN) {
Expand Down Expand Up @@ -2303,6 +2309,10 @@ function baseCreateRenderer(
)
}
queuePostRenderEffect(() => {
if (instance.hoistedVNodes) {
instance.hoistedVNodes.forEach(vnode => (vnode.el = null))
instance.hoistedVNodes = null
}
instance.isUnmounted = true
}, parentSuspense)

Expand Down