@@ -35,10 +35,17 @@ export const VaporTeleportImpl = {
3535 rawPropsProxyHandlers ,
3636 ) as any as TeleportProps
3737
38+ let children : Block
39+
40+ renderEffect ( ( ) => {
41+ frag . updateChildren (
42+ ( children = slots . default && ( slots . default as BlockFn ) ( ) ) ,
43+ )
44+ } )
45+
3846 renderEffect ( ( ) => {
39- const children = slots . default && ( slots . default as BlockFn ) ( )
4047 // access the props to trigger tracking
41- frag . update ( extend ( { } , resolvedProps ) , children )
48+ frag . update ( extend ( { } , resolvedProps ) , children ! )
4249 } )
4350
4451 return frag
@@ -50,26 +57,42 @@ export class TeleportFragment extends VaporFragment {
5057 targetStart ?: Node | null
5158 mainAnchor ?: Node
5259 placeholder ?: Node
53- currentParent ?: ParentNode | null
60+ container ?: ParentNode | null
61+ currentAnchor ?: Node | null
5462
5563 constructor ( anchorLabel ?: string ) {
5664 super ( [ ] )
5765 this . anchor =
5866 __DEV__ && anchorLabel ? createComment ( anchorLabel ) : createTextNode ( )
5967 }
6068
61- update ( props : TeleportProps , children : Block ) : void {
69+ updateChildren ( children : Block ) : void {
6270 const parent = this . anchor . parentNode
71+ if ( ! parent ) return
72+
73+ const container = this . container || parent
74+
6375 // teardown previous
64- if ( this . nodes && ( this . currentParent || parent ) ) {
65- remove ( this . nodes , ( this . currentParent || parent ) ! )
66- }
76+ remove ( this . nodes , container )
77+
78+ insert (
79+ ( this . nodes = children ) ,
80+ container ,
81+ this . currentAnchor || this . anchor ,
82+ )
83+ }
6784
85+ update ( props : TeleportProps , children : Block ) : void {
86+ const parent = this . anchor . parentNode
6887 this . nodes = children
6988 const disabled = isTeleportDisabled ( props )
7089
7190 const mount = ( parent : ParentNode , anchor : Node | null ) => {
72- insert ( this . nodes , ( this . currentParent = parent ) , anchor )
91+ insert (
92+ this . nodes ,
93+ ( this . container = parent ) ,
94+ ( this . currentAnchor = anchor ) ,
95+ )
7396 }
7497
7598 const mountToTarget = ( ) => {
@@ -124,7 +147,7 @@ export class TeleportFragment extends VaporFragment {
124147
125148 remove = ( parent : ParentNode | undefined ) : void => {
126149 // remove nodes
127- remove ( this . nodes , this . currentParent || parent )
150+ remove ( this . nodes , this . container || parent )
128151
129152 // remove anchors
130153 if ( this . targetStart ) {
0 commit comments