Skip to content
Merged
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
15 changes: 11 additions & 4 deletions packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export class EffectScope implements ReactiveNode {
return
}
this.flags = EffectFlags.STOP
this.reset()
const sub = this.subs
if (sub !== undefined) {
unlink(sub)
}
}

/**
* @internal
*/
reset(): void {
let dep = this.deps
while (dep !== undefined) {
const node = dep.dep
Expand All @@ -83,10 +94,6 @@ export class EffectScope implements ReactiveNode {
dep = unlink(dep, this)
}
}
const sub = this.subs
if (sub !== undefined) {
unlink(sub)
}
cleanup(this)
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ function reload(id: string, newComp: HMRComponent): void {
if (!record) return

newComp = normalizeClassComponent(newComp)
const isVapor = record.initialDef.__vapor
// update initial def (for not-yet-rendered components)
updateComponentDef(record.initialDef, newComp)

// create a snapshot which avoids the set being mutated during updates
const instances = [...record.instances]

if (newComp.__vapor && !instances.some(i => i.ceReload)) {
if (isVapor && newComp.__vapor && !instances.some(i => i.ceReload)) {
// For multiple instances with the same __hmrId, remove styles first before reload
// to avoid the second instance's style removal deleting the first instance's
// newly added styles (since hmrReload is synchronous)
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ export class VaporComponentInstance<
asyncDep: Promise<any> | null
asyncResolved: boolean

// for HMR and vapor custom element
// all render effects associated with this instance
// for vapor custom element
renderEffects?: RenderEffect[]

hasFallthrough: boolean
Expand Down
6 changes: 2 additions & 4 deletions packages/runtime-vapor/src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ export function hmrRerender(instance: VaporComponentInstance): void {
const normalized = normalizeBlock(instance.block)
const parent = normalized[0].parentNode!
const anchor = normalized[normalized.length - 1].nextSibling
// reset scope to avoid stale effects
instance.scope.reset()
remove(instance.block, parent)
const prev = setCurrentInstance(instance)
if (instance.renderEffects) {
instance.renderEffects.forEach(e => e.stop())
instance.renderEffects = []
}
pushWarningContext(instance)
devRender(instance)
popWarningContext()
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-vapor/src/renderEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class RenderEffect extends ReactiveEffect {
: void 0
}

if (__DEV__ || instance.type.ce) {
// register effect for stopping them during HMR rerender
// register effect for vapor custom element update
if (instance.type.ce) {
;(instance.renderEffects || (instance.renderEffects = [])).push(this)
}
job.i = instance
Expand Down
Loading