Skip to content

Commit 01b74e9

Browse files
committed
fix(hmr): update hmrRerender to accept dirtyInstance for proper unmounting
1 parent 39ca181 commit 01b74e9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

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?: () => void
551+
hmrRerender?: (dirtyInstance?: any) => void
552552
/**
553553
* @internal vapor only
554554
*/

packages/runtime-core/src/hmr.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ function reload(id: string, newComp: HMRComponent): void {
172172
isHmrUpdating = true
173173
const parent = instance.parent! as ComponentInternalInstance
174174
if (parent.vapor) {
175-
// ensure unregisterHMR is called to avoid stale instances
176-
instance.scope.stop()
177-
parent.hmrRerender!()
175+
parent.hmrRerender!(instance)
178176
} else {
179177
if (!(parent.effect.flags! & EffectFlags.STOP)) {
180178
parent.renderCache = []

packages/runtime-vapor/src/hmr.ts

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

18-
export function hmrRerender(instance: VaporComponentInstance): void {
18+
export function hmrRerender(
19+
instance: VaporComponentInstance,
20+
dirtyInstance?: VaporComponentInstance,
21+
): void {
1922
const normalized = normalizeBlock(instance.block)
2023
const parent = normalized[0].parentNode!
2124
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)
2228
remove(instance.block, parent)
2329
const prev = setCurrentInstance(instance)
2430
if (instance.renderEffects) {
@@ -38,8 +44,7 @@ export function hmrReload(
3844
): void {
3945
// if parent is KeepAlive, we need to rerender it
4046
if (instance.parent && isKeepAlive(instance.parent)) {
41-
instance.scope.stop()
42-
instance.parent.hmrRerender!()
47+
instance.parent.hmrRerender!(instance)
4348
return
4449
}
4550
const normalized = normalizeBlock(instance.block)

0 commit comments

Comments
 (0)