From b1fb98fb9b7b21131b9976d1871ad8d77d2a5c0b Mon Sep 17 00:00:00 2001 From: tatsuya-asami Date: Sat, 9 May 2026 15:01:47 +0900 Subject: [PATCH] [compiler]: add `useFormContext` to react-hook-form known incompatible APIs #34027 added a check for react-hook-form's `useForm().watch`, but not `useFormContext().watch`. The same `watch` function is exposed via `useFormContext()` and has the same memoization incompatibility, also discussed in the community at https://github.com/orgs/react-hook-form/discussions/12524. --- .../src/HIR/DefaultModuleTypeProvider.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts index 106fce615c44..9c27696396ad 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts @@ -65,6 +65,24 @@ export function defaultModuleTypeProvider( }, }, }, + useFormContext: { + kind: 'hook', + returnType: { + kind: 'object', + properties: { + // Only the `watch()` function returned by react-hook-form's `useFormContext()` API is incompatible + watch: { + kind: 'function', + positionalParams: [], + restParam: Effect.Read, + calleeEffect: Effect.Read, + returnType: {kind: 'type', name: 'Any'}, + returnValueKind: ValueKind.Mutable, + knownIncompatible: `React Hook Form's \`useFormContext()\` API returns a \`watch()\` function which cannot be memoized safely.`, + }, + }, + }, + }, }, }; }