Skip to content

[compiler] Add useFormContext to known incompatible libraries - #35465

Closed
reyronald wants to merge 2 commits into
react:mainfrom
reyronald:reyronald-useformcontext-incompatible-library
Closed

[compiler] Add useFormContext to known incompatible libraries#35465
reyronald wants to merge 2 commits into
react:mainfrom
reyronald:reyronald-useformcontext-incompatible-library

Conversation

@reyronald

@reyronald reyronald commented Jan 8, 2026

Copy link
Copy Markdown

The original implementation in #34027 added useForm from react-hook-form to the known incompatible libraries list, but missed useFormContext. useFormContext returns the same API surface as useForm, including the watch() function that cannot be memoized safely.

This PR adds useFormContext with the same configuration as useForm

I repurposed @Maxou44 's original repro repo from react-hook-form/react-hook-form#11910 to demonstrate that the issue can be reproduced with useFormContext too, you can play around with the updated demo if you want to confirm, repo link below

https://github.com/reyronald/issue-react-compiler-react-hook-form

Repro details
import {
  useForm,
  useWatch,
  useFormContext,
  FormProvider,
} from "react-hook-form";

export default function App() {
  const methods = useForm();
  const { register, handleSubmit, watch, control } = methods;
  const onSubmit = (data) => console.log(data);

  const test = useWatch({ control, name: "test" });

  return (
    <div>
      <Headers description="Performant, flexible and extensible forms with easy-to-use validation." />

      <FormProvider {...methods}>
        <form onSubmit={handleSubmit(onSubmit)}>
          <input {...register("test")} placeholder="Test field" />

          <div>useForm.watch is {watch("test")}</div>

          <div>useForm.useWatch value is {test}</div>

          <Component />

          <input type="submit" />
        </form>
      </FormProvider>
    </div>
  );
}

function Component() {
  const { watch, control } = useFormContext();

  const test = useWatch({ control, name: "test" });

  return (
    <>
      <div>useFormContext.watch is {watch("test")}</div>

      <div>useForm.useWatch value is {test}</div>
    </>
  );
}
image

References

  1. issue: Watch don't work with React Compiler (React 19) react-hook-form/react-hook-form#11910
  2. [compiler] Detect known incompatible libraries #34027
  3. [compiler]: add @tanstack/react-virtual to known incompatible libraries #34493

The original implementation in react#34027 added useForm from react-hook-form
to the known incompatible libraries list, but missed useFormContext.
useFormContext returns the same API surface as useForm, including the
watch() function that cannot be memoized safely.

This PR adds useFormContext with the same configuration as useForm

I repurposed @Maxou44 's original repro repo from react#11910 to demonstrate
that the issue can be reproduced with useFormContext too, you can play
around with the updated demo if you want to confirm, repo link below

https://github.com/reyronald/issue-react-compiler-react-hook-form
@meta-cla meta-cla Bot added the CLA Signed label Jan 8, 2026
@Maxou44

Maxou44 commented Jan 8, 2026

Copy link
Copy Markdown

Can you try using the beta 8.0.0 of React Hook Form ?

@reyronald

Copy link
Copy Markdown
Author

Can you try using the beta 8.0.0 of React Hook Form ?

@Maxou44 Issue cannot be reproduced in 8.0.0-beta.0

$  npm ls react-hook-form
└── react-hook-form@8.0.0-beta.0
image

However, it doesn't seem like the linter takes into account the version of the library, just its name, so it's worth adding regardless, thoughts?

@Maxou44

Maxou44 commented Jan 8, 2026

Copy link
Copy Markdown

I don't have any issues using 8.0.0, I don't know how the React team want to handle this case 😅

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions Bot added the Resolution: Stale Automatically closed due to inactivity label Jun 8, 2026
@github-actions

Copy link
Copy Markdown

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions Bot closed this Jun 15, 2026
@Maxou44

Maxou44 commented Jun 15, 2026

Copy link
Copy Markdown

Issue is still present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Resolution: Stale Automatically closed due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants