Skip to content

Commit bae18b4

Browse files
committed
[compiler] Add flag for lowering context access
*This is only for internal profiling, not intended to ship.* ghstack-source-id: e48998b Pull Request resolved: #30547
1 parent f5f9899 commit bae18b4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,25 @@ const EnvironmentConfigSchema = z.object({
434434
* Here the variables `ref` and `myRef` will be typed as Refs.
435435
*/
436436
enableTreatRefLikeIdentifiersAsRefs: z.boolean().nullable().default(false),
437+
438+
/*
439+
* If enabled, this lowers any calls to `useContext` hook to use a selector
440+
* function.
441+
*
442+
* The compiler automatically figures out the keys by looking for the immediate
443+
* destructuring of the return value from the useContext call. In the future,
444+
* this can be extended to different kinds of context access like property
445+
* loads and accesses over multiple statements as well.
446+
*
447+
* ```
448+
* // input
449+
* const {foo, bar} = useContext(MyContext);
450+
*
451+
* // output
452+
* const {foo, bar} = useContext(MyContext, (c) => [c.foo, c.bar]);
453+
* ```
454+
*/
455+
enableLowerContextAccess: z.boolean().nullable().default(false),
437456
});
438457

439458
export type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;

0 commit comments

Comments
 (0)