Skip to content

Commit 90c2e20

Browse files
committed
wip: hmr updating
1 parent 51ca617 commit 90c2e20

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

packages/runtime-vapor/src/component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ export function createComponent(
172172
frag.hydrate()
173173
}
174174

175+
// remove the teleport content from the parent tree for HMR updates
175176
if (__DEV__) {
176177
const instance = currentInstance as VaporComponentInstance
177-
;(instance!.hmrEffects || (instance!.hmrEffects = [])).push(() =>
178-
frag.remove(frag.anchor.parentNode!),
179-
)
178+
;(instance!.hmrEffects || (instance!.hmrEffects = [])).push(() => {
179+
frag.remove(frag.anchor.parentNode!)
180+
})
180181
}
181182

182183
return frag as any

packages/runtime-vapor/src/components/Teleport.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { LooseRawProps, LooseRawSlots } from '../component'
1919
import { rawPropsProxyHandlers } from '../componentProps'
2020
import { renderEffect } from '../renderEffect'
2121
import { extend } from '@vue/shared'
22+
import { EffectScope, pauseTracking, resetTracking } from '@vue/reactivity'
2223

2324
export const VaporTeleportImpl = {
2425
name: 'VaporTeleport',
@@ -30,30 +31,36 @@ export const VaporTeleportImpl = {
3031
? new TeleportFragment('teleport')
3132
: new TeleportFragment()
3233

33-
let children: Block
34-
renderEffect(() => {
35-
frag.updateChildren(
36-
(children = slots.default && (slots.default as BlockFn)()),
37-
)
38-
})
39-
40-
renderEffect(() => {
41-
frag.update(
42-
// access the props to trigger tracking
43-
extend(
44-
{},
45-
new Proxy(props, rawPropsProxyHandlers) as any as TeleportProps,
46-
),
47-
children!,
48-
)
34+
pauseTracking()
35+
const scope = (frag.scope = new EffectScope())
36+
scope!.run(() => {
37+
let children: Block
38+
renderEffect(() => {
39+
frag.updateChildren(
40+
(children = slots.default && (slots.default as BlockFn)()),
41+
)
42+
})
43+
44+
renderEffect(() => {
45+
frag.update(
46+
// access the props to trigger tracking
47+
extend(
48+
{},
49+
new Proxy(props, rawPropsProxyHandlers) as any as TeleportProps,
50+
),
51+
children!,
52+
)
53+
})
4954
})
55+
resetTracking()
5056

5157
return frag
5258
},
5359
}
5460

5561
class TeleportFragment extends VaporFragment {
5662
anchor: Node
63+
scope: EffectScope | undefined
5764

5865
private targetStart?: Node
5966
private mainAnchor?: Node
@@ -155,17 +162,31 @@ class TeleportFragment extends VaporFragment {
155162
}
156163

157164
remove = (parent: ParentNode | undefined): void => {
165+
// stop effect scope
166+
if (this.scope) {
167+
this.scope.stop()
168+
this.scope = undefined
169+
}
170+
158171
// remove nodes
159-
remove(this.nodes, this.currentParent)
172+
if (this.nodes) {
173+
remove(this.nodes, this.currentParent)
174+
this.nodes = []
175+
}
160176

161177
// remove anchors
162178
if (this.targetStart) {
163179
remove(this.targetStart!, this.target!)
180+
this.targetStart = undefined
164181
remove(this.targetAnchor!, this.target!)
182+
this.targetAnchor = undefined
165183
}
184+
166185
if (this.placeholder) {
167186
remove(this.placeholder!, parent)
187+
this.placeholder = undefined
168188
remove(this.mainAnchor!, parent)
189+
this.mainAnchor = undefined
169190
}
170191
}
171192

0 commit comments

Comments
 (0)