Skip to content

Commit 09c786b

Browse files
committed
fix(hmr): refactor scope cleanup to use reset method for stale effects management
1 parent 56f2668 commit 09c786b

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

packages/reactivity/src/effectScope.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ export class EffectScope implements ReactiveNode {
7373
return
7474
}
7575
this.flags = EffectFlags.STOP
76+
this.reset()
77+
const sub = this.subs
78+
if (sub !== undefined) {
79+
unlink(sub)
80+
}
81+
}
82+
83+
/**
84+
* @internal
85+
*/
86+
reset(): void {
7687
let dep = this.deps
7788
while (dep !== undefined) {
7889
const node = dep.dep
@@ -83,17 +94,6 @@ export class EffectScope implements ReactiveNode {
8394
dep = unlink(dep, this)
8495
}
8596
}
86-
const sub = this.subs
87-
if (sub !== undefined) {
88-
unlink(sub)
89-
}
90-
this.cleanup()
91-
}
92-
93-
/**
94-
* @internal
95-
*/
96-
cleanup(): void {
9797
cleanup(this)
9898
}
9999
}

packages/runtime-vapor/src/component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ export class VaporComponentInstance<
592592
asyncDep: Promise<any> | null
593593
asyncResolved: boolean
594594

595-
// for HMR and vapor custom element
596-
// all render effects associated with this instance
595+
// for vapor custom element
597596
renderEffects?: RenderEffect[]
598597

599598
hasFallthrough: boolean

packages/runtime-vapor/src/hmr.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ export function hmrRerender(instance: VaporComponentInstance): void {
1919
const normalized = normalizeBlock(instance.block)
2020
const parent = normalized[0].parentNode!
2121
const anchor = normalized[normalized.length - 1].nextSibling
22-
// cleanup scope, ensure child components are unregister hmr and unmount
23-
instance.scope.cleanup()
22+
// reset scope to avoid stale effects
23+
instance.scope.reset()
2424
remove(instance.block, parent)
2525
const prev = setCurrentInstance(instance)
26-
if (instance.renderEffects) {
27-
instance.renderEffects.forEach(e => e.stop())
28-
instance.renderEffects = []
29-
}
3026
pushWarningContext(instance)
3127
devRender(instance)
3228
popWarningContext()

packages/runtime-vapor/src/renderEffect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class RenderEffect extends ReactiveEffect {
4444
: void 0
4545
}
4646

47-
if (__DEV__ || instance.type.ce) {
48-
// register effect for stopping them during HMR rerender
47+
// register effect for vapor custom element update
48+
if (instance.type.ce) {
4949
;(instance.renderEffects || (instance.renderEffects = [])).push(this)
5050
}
5151
job.i = instance

0 commit comments

Comments
 (0)