From 7af1c8919a5f0199af0c3dc4b11e3378b300f897 Mon Sep 17 00:00:00 2001 From: MorikawaSouma Date: Fri, 13 Mar 2026 09:40:17 +0800 Subject: [PATCH] fix(compiler): recognize 'use' as a hook for hook detection React's 'use()' API is a hook for reading context and promises, but the compiler's isHookName() function only matched 'use[A-Z0-9]' pattern, causing custom hooks that only call use() to be silently skipped during compilation. This fix adds 'use' to the hook name recognition so that functions like: function useMyContext() { return use(MyContext); } will now be correctly compiled with memoization. Fixes #35960 --- .../babel-plugin-react-compiler/src/Entrypoint/Program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts index 2880e9283c..673a63b2c3 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts @@ -895,7 +895,7 @@ function hasMemoCacheFunctionImport( } function isHookName(s: string): boolean { - return /^use[A-Z0-9]/.test(s); + return s === 'use' || /^use[A-Z0-9]/.test(s); } /*