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): during the hmr reload process, instance.update should not allow recursing (fix #7908) #8161

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
26 changes: 25 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import {
ComponentInternalInstance,
ComponentOptions,
ConcreteComponent,
createComponentInstance,
Data,
setupComponent
Expand Down Expand Up @@ -58,7 +59,12 @@ import {
} from './components/Suspense'
import { TeleportImpl, TeleportVNode } from './components/Teleport'
import { isKeepAlive, KeepAliveContext } from './components/KeepAlive'
import { registerHMR, unregisterHMR, isHmrUpdating } from './hmr'
import {
registerHMR,
unregisterHMR,
isHmrUpdating,
hmrDirtyComponents
} from './hmr'
import { createHydrationFunctions, RootHydrateFunction } from './hydration'
import { invokeDirectiveHook } from './directives'
import { startMeasure, endMeasure } from './profiling'
Expand Down Expand Up @@ -1491,6 +1497,19 @@ function baseCreateRenderer(
if (__DEV__) {
startMeasure(instance, `patch`)
}
/**
* #7908
* During the hmr reload process, in some cases (such as "ref + v-for"),
* instance.update will be triggered twice.
*/
const isHmrReload = hmrDirtyComponents.has(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All HMR related code should be inside __DEV__ branches for treeshaking.

nextTree.type as ConcreteComponent
)

if (isHmrReload) {
toggleRecurse(instance, false)
}

patch(
prevTree,
nextTree,
Expand All @@ -1502,6 +1521,11 @@ function baseCreateRenderer(
parentSuspense,
isSVG
)

if (isHmrReload) {
toggleRecurse(instance, true)
}

if (__DEV__) {
endMeasure(instance, `patch`)
}
Expand Down