Skip to content

Commit

Permalink
fix(runtime-core): component my come from js file, it do not have __h…
Browse files Browse the repository at this point in the history
…mrId (fix vuejs#7921)
  • Loading branch information
Jevon617 committed Apr 17, 2023
1 parent 4e028b9 commit d35311f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,15 @@ export function updateHOCHostEl(
parent = parent.parent
}
}

export function traverseParentHmrId(
component: ComponentInternalInstance | null
) {
while (component) {
if (component.type.__hmrId) {
return true
}
component = component.parent
}
return false
}
11 changes: 10 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
filterSingleRoot,
renderComponentRoot,
shouldUpdateComponent,
traverseParentHmrId,
updateHOCHostEl
} from './componentRenderUtils'
import {
Expand Down Expand Up @@ -1110,7 +1111,15 @@ function baseCreateRenderer(
isSVG,
slotScopeIds
)
if (__DEV__ && parentComponent && parentComponent.type.__hmrId) {
// #7921 The parentComponent may come from a js file in node_modules,
// and such components do not have __hmrId.
// In this case, their hmr status depends on their ancestor components.
// Therefore, we need to traverse and check whether their ancestor components have __hmrId.
if (
__DEV__ &&
parentComponent &&
traverseParentHmrId(parentComponent)
) {
traverseStaticChildren(n1, n2)
} else if (
// #2080 if the stable fragment has a key, it's a <template v-for> that may
Expand Down

0 comments on commit d35311f

Please sign in to comment.