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): the component may come from a js file, it does not have __hmrId (fix #7921) #8100

Closed
wants to merge 1 commit 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
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