You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/react-guidelines/react-compiler.md
+57Lines changed: 57 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ If you find existing `useMemo` or `useCallback` calls in compiler-enabled code,
17
17
> - The component still has compiler violations (check `.react-compiler.rec.json`)
18
18
> - The compiler is not enabled in the project
19
19
> - The memoized value is defined before other hook calls that separate it from its hook consumer (e.g., `useState`, `useEffect`). The compiler silently skips memoization in this case, even though the file compiles without errors. See [Memoization gap with intervening hooks](#memoization-gap-with-intervening-hooks).
20
+
> - The value comes from a `use`-prefixed function that contains no actual hook calls. The compiler treats these as hooks and cannot cache their return values. See [Hook-named helper functions prevent return-value memoization](#hook-named-helper-functions-prevent-return-value-memoization).
> This is not a compiler error. The file compiles cleanly and passes
1153
+
> `react-compiler-tracker--check-files`, but the compiler silently skips
1154
+
> memoization it would otherwise apply.
1155
+
1156
+
Any function named `use` + uppercase letter is treated as a hook, even if it contains no hook calls. This causes two missed optimizations:
1157
+
1158
+
1. **At the call site**, the compiler must invoke hooks unconditionally every render (Rules of Hooks), so the return value cannot be cached.
1159
+
2. **At the definition site**, the compiler [skips functions that look like hooks but contain no hook calls or JSX](https://github.com/facebook/react/issues/31727). The function body is never compiled, so expressions inside it (like array literals) are never memoized either.
1160
+
1161
+
**Fix:** Rename the function to `get`, `create`, `build`, or another non-hook prefix at the definition/export site.
0 commit comments