@@ -47,6 +47,7 @@ import {
47
47
CHILD ,
48
48
TREE ,
49
49
PARENT ,
50
+ SEEN_TREE_NODES ,
50
51
} from './shared' ;
51
52
import { isRehydrationScheduled } from './ssr/rehydration' ;
52
53
import { createHotReload } from './hmr' ;
@@ -788,14 +789,26 @@ export const $_maybeHelper = (
788
789
return value ;
789
790
} ;
790
791
791
- let parentContext : Root | Component < any > | null = null ;
792
+ let parentContext : Array < number > = [ ] ;
793
+ let parentContextIndex = - 1 ;
792
794
793
795
export const setParentContext = ( value : Root | Component < any > | null ) => {
794
- parentContext = value ;
795
- }
796
+ if ( value === null ) {
797
+ parentContextIndex -- ;
798
+ parentContext . pop ( ) ;
799
+ } else {
800
+ parentContextIndex ++ ;
801
+ parentContext . push ( value [ COMPONENT_ID_PROPERTY ] ! ) ;
802
+ }
803
+ } ;
796
804
export const getParentContext = ( ) => {
797
- return parentContext ;
798
- }
805
+ if ( IS_DEV_MODE ) {
806
+ if ( ! TREE . get ( parentContext [ parentContextIndex ] ! ) ) {
807
+ throw new Error ( 'unable to get parent context before set' ) ;
808
+ }
809
+ }
810
+ return TREE . get ( parentContext [ parentContextIndex ] ! ) ;
811
+ } ;
799
812
800
813
function component (
801
814
comp : ComponentReturnType | Component | typeof Component ,
@@ -1177,7 +1190,9 @@ export function $_GET_ARGS(ctx: Component<any>, args: IArguments) {
1177
1190
ctx [ $args ] = ctx [ $args ] || args [ 0 ] || { } ;
1178
1191
ctx [ RENDERED_NODES_PROPERTY ] = ctx [ RENDERED_NODES_PROPERTY ] ?? [ ] ;
1179
1192
ctx [ COMPONENT_ID_PROPERTY ] = ctx [ COMPONENT_ID_PROPERTY ] ?? cId ( ) ;
1180
- addToTree ( getParentContext ( ) ! , ctx ) ;
1193
+ if ( ! SEEN_TREE_NODES . has ( ctx ) ) {
1194
+ addToTree ( getParentContext ( ) ! , ctx ) ;
1195
+ }
1181
1196
}
1182
1197
export function $_GET_SLOTS ( ctx : any , args : any ) {
1183
1198
return ( args [ 0 ] || { } ) [ $SLOTS_SYMBOL ] || ctx [ $args ] ?. [ $SLOTS_SYMBOL ] || { } ;
0 commit comments