From b6450e8f2d89235350932e332195f8549dcf2391 Mon Sep 17 00:00:00 2001 From: lauren Date: Mon, 21 Jul 2025 18:11:57 -0400 Subject: [PATCH] [compiler] Add note about gating evaluation (#7891) * [compiler] Flesh out incremental adoption intro more Previously the intro was pretty barebones. Fleshed it out a bit more to describe why it might be useful to reach for in a large codebase. * [compiler] Add note about gating evaluation Clarify when the gating function is evaluated. --- src/content/reference/react-compiler/gating.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/reference/react-compiler/gating.md b/src/content/reference/react-compiler/gating.md index 2959c49fa..479506af3 100644 --- a/src/content/reference/react-compiler/gating.md +++ b/src/content/reference/react-compiler/gating.md @@ -63,7 +63,7 @@ Configures runtime feature flag gating for compiled functions. // src/utils/feature-flags.js export function shouldUseCompiler() { // your logic here - return Math.random() < 0.5; + return getFeatureFlag('react-compiler-enabled'); } ``` @@ -94,6 +94,8 @@ const Button = shouldUseCompiler() : function Button_original(props) { /* original version */ }; ``` +Note that the gating function is evaluated once at module time, so once the JS bundle has been parsed and evaluated the choice of component stays static for the rest of the browser session. + --- ## Troubleshooting {/*troubleshooting*/}