@@ -40,7 +40,6 @@ import {
40
40
IN_SSR_ENV ,
41
41
COMPONENTS_HMR ,
42
42
isEmpty ,
43
- $context ,
44
43
RENDERING_CONTEXT_PROPERTY ,
45
44
RENDERED_NODES_PROPERTY ,
46
45
COMPONENT_ID_PROPERTY ,
@@ -789,6 +788,15 @@ export const $_maybeHelper = (
789
788
return value ;
790
789
} ;
791
790
791
+ let parentContext : Root | Component < any > | null = null ;
792
+
793
+ export const setParentContext = ( value : Root | Component < any > | null ) => {
794
+ parentContext = value ;
795
+ }
796
+ export const getParentContext = ( ) => {
797
+ return parentContext ;
798
+ }
799
+
792
800
function component (
793
801
comp : ComponentReturnType | Component | typeof Component ,
794
802
args : Record < string , unknown > ,
@@ -820,6 +828,7 @@ function component(
820
828
}
821
829
// @ts -expect-error uniqSymbol as index
822
830
const fw = args [ $PROPS_SYMBOL ] as unknown as FwType ;
831
+ setParentContext ( ctx ) ;
823
832
return _component ( comp , args , fw , ctx ) ;
824
833
} catch ( e ) {
825
834
if ( import . meta. env . SSR ) {
@@ -862,14 +871,20 @@ function component(
862
871
} ;
863
872
}
864
873
} finally {
874
+ setParentContext ( null ) ;
865
875
if ( IS_DEV_MODE ) {
866
876
$DEBUG_REACTIVE_CONTEXTS . pop ( ) ;
867
877
}
868
878
}
869
879
} else {
870
880
// @ts -expect-error uniqSymbol as index
871
881
const fw = args [ $PROPS_SYMBOL ] as unknown as FwType ;
872
- return _component ( comp , args , fw , ctx ) ;
882
+ try {
883
+ setParentContext ( ctx ) ;
884
+ return _component ( comp , args , fw , ctx ) ;
885
+ } finally {
886
+ setParentContext ( null ) ;
887
+ }
873
888
}
874
889
}
875
890
// hello, basic component manager
@@ -879,7 +894,6 @@ function _component(
879
894
fw : FwType ,
880
895
ctx : Component < any > | Root ,
881
896
) {
882
- args [ $context ] = ctx ;
883
897
let startTagId = 0 ;
884
898
if ( IS_DEV_MODE ) {
885
899
startTagId = getTagId ( ) ;
@@ -975,9 +989,7 @@ function createSlot(
975
989
$DEBUG_REACTIVE_CONTEXTS . push ( `:${ name } ` ) ;
976
990
}
977
991
const slotContext = {
978
- [ $args ] : {
979
- [ $context ] : ctx ,
980
- } ,
992
+ [ $args ] : { } ,
981
993
[ RENDERED_NODES_PROPERTY ] : [ ] ,
982
994
[ COMPONENT_ID_PROPERTY ] : cId ( ) ,
983
995
[ RENDERING_CONTEXT_PROPERTY ] : null ,
@@ -1154,12 +1166,7 @@ const ArgProxyHandler: ProxyHandler<{}> = {
1154
1166
}
1155
1167
return undefined ;
1156
1168
} ,
1157
- set ( target , prop , value ) {
1158
- if ( prop === $context ) {
1159
- // @ts -expect-error unknown property
1160
- target [ prop ] = value ;
1161
- return true ;
1162
- }
1169
+ set ( ) {
1163
1170
if ( IS_DEV_MODE ) {
1164
1171
throw new Error ( 'args are readonly' ) ;
1165
1172
}
@@ -1170,13 +1177,7 @@ export function $_GET_ARGS(ctx: Component<any>, args: IArguments) {
1170
1177
ctx [ $args ] = ctx [ $args ] || args [ 0 ] || { } ;
1171
1178
ctx [ RENDERED_NODES_PROPERTY ] = ctx [ RENDERED_NODES_PROPERTY ] ?? [ ] ;
1172
1179
ctx [ COMPONENT_ID_PROPERTY ] = ctx [ COMPONENT_ID_PROPERTY ] ?? cId ( ) ;
1173
- const parentContext = ctx [ $args ] [ $context ] || args [ 0 ] [ $context ] ;
1174
- if ( IS_DEV_MODE ) {
1175
- if ( ! parentContext ) {
1176
- throw new Error ( `Unable to resolve parent context` ) ;
1177
- }
1178
- }
1179
- addToTree ( parentContext , ctx ) ;
1180
+ addToTree ( getParentContext ( ) ! , ctx ) ;
1180
1181
}
1181
1182
export function $_GET_SLOTS ( ctx : any , args : any ) {
1182
1183
return ( args [ 0 ] || { } ) [ $SLOTS_SYMBOL ] || ctx [ $args ] ?. [ $SLOTS_SYMBOL ] || { } ;
0 commit comments