Skip to content

[compiler] Fix custom hook with use() not being compiled#35964

Open
carlbergman wants to merge 2 commits intofacebook:mainfrom
carlbergman:compiler-hook-with-use-api-fix
Open

[compiler] Fix custom hook with use() not being compiled#35964
carlbergman wants to merge 2 commits intofacebook:mainfrom
carlbergman:compiler-hook-with-use-api-fix

Conversation

@carlbergman
Copy link

Summary

Fix detection of use() in custom hooks for infer mode. The isHookName check used the regex /^use[A-Z0-9]/ which doesn't match use. This caused custom hooks whose only invocation is use() to be skipped in infer mode.

This is the second PR per the development guide. The first PR is #35963.

Fixes #35960

How did you test this change?

yarn snap

Custom hooks whose only invocation is the `use()` function are
skipped by the compiler. This fixture demonstrates the
current (broken) output where `useMyContext` is not compiled.

Ref facebook#35960
The `isHookName` check in Program.ts used the regex `/^use[A-Z0-9]/`
which doesn't match `use()`. This caused custom hooks whose only
invocation is `use()` to be skipped in infer mode.

Fixes facebook#35960
@meta-cla meta-cla bot added the CLA Signed label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler Bug]: React Compiler silently skips custom hooks whose only hook call is use()

1 participant