@@ -19,6 +19,7 @@ import type { LooseRawProps, LooseRawSlots } from '../component'
1919import { rawPropsProxyHandlers } from '../componentProps'
2020import { renderEffect } from '../renderEffect'
2121import { extend } from '@vue/shared'
22+ import { EffectScope , pauseTracking , resetTracking } from '@vue/reactivity'
2223
2324export 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
5561class 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