Skip to content

Commit 56f2668

Browse files
committed
fix(hmr): refactor hmrRerender to remove dirtyInstance parameter and ensure proper cleanup
1 parent 01b74e9 commit 56f2668

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ export class EffectScope implements ReactiveNode {
8787
if (sub !== undefined) {
8888
unlink(sub)
8989
}
90+
this.cleanup()
91+
}
92+
93+
/**
94+
* @internal
95+
*/
96+
cleanup(): void {
9097
cleanup(this)
9198
}
9299
}

packages/runtime-core/src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ export interface GenericComponentInstance {
548548
/**
549549
* @internal vapor only
550550
*/
551-
hmrRerender?: (dirtyInstance?: any) => void
551+
hmrRerender?: () => void
552552
/**
553553
* @internal vapor only
554554
*/

packages/runtime-core/src/hmr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function reload(id: string, newComp: HMRComponent): void {
172172
isHmrUpdating = true
173173
const parent = instance.parent! as ComponentInternalInstance
174174
if (parent.vapor) {
175-
parent.hmrRerender!(instance)
175+
parent.hmrRerender!()
176176
} else {
177177
if (!(parent.effect.flags! & EffectFlags.STOP)) {
178178
parent.renderCache = []

packages/runtime-vapor/src/hmr.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ import {
1515
} from './component'
1616
import { isArray } from '@vue/shared'
1717

18-
export function hmrRerender(
19-
instance: VaporComponentInstance,
20-
dirtyInstance?: VaporComponentInstance,
21-
): void {
18+
export function hmrRerender(instance: VaporComponentInstance): void {
2219
const normalized = normalizeBlock(instance.block)
2320
const parent = normalized[0].parentNode!
2421
const anchor = normalized[normalized.length - 1].nextSibling
25-
// When dirty instance is provided, instance is its parent component
26-
// and dirty instance needs to be unmount to ensure unregister HMR
27-
if (dirtyInstance) unmountComponent(dirtyInstance)
22+
// cleanup scope, ensure child components are unregister hmr and unmount
23+
instance.scope.cleanup()
2824
remove(instance.block, parent)
2925
const prev = setCurrentInstance(instance)
3026
if (instance.renderEffects) {
@@ -44,7 +40,7 @@ export function hmrReload(
4440
): void {
4541
// if parent is KeepAlive, we need to rerender it
4642
if (instance.parent && isKeepAlive(instance.parent)) {
47-
instance.parent.hmrRerender!(instance)
43+
instance.parent.hmrRerender!()
4844
return
4945
}
5046
const normalized = normalizeBlock(instance.block)

0 commit comments

Comments
 (0)