Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve error when not passing control to useController #11028

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MeLlamoPablo
Copy link

@MeLlamoPablo MeLlamoPablo commented Oct 10, 2023

Proposed Changes

This PR improves the message of the error that is generated when you don't pass control to Controller or useController. This error occurs if you neither pass control as a prop directly nor provide control via FormProvider.

Currently, you would get a rather cryptic "methods is null" error:

image

After this PR, you get a more informative error:

Screenshot 2023-10-10 at 19 03 48

Interestingly, while the console stack trace is able to pinpoint useController as the source for both errors, Next.js can only understand that this error happens in the code of the library if it's explicitly thrown. Before this PR, Next.js thinks that the error happens in my code.

While to most users of the library it should be obvious that you need to somehow pass control to Controller, when developing you can easily get tunnel vision and forget about basic mechanisms, as happened to me. This PR should help developers get back on track without having to spend a lot of time understanding what they did wrong.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

@codesandbox
Copy link

codesandbox bot commented Oct 10, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

stale bot commented Mar 13, 2024

Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️

@stale stale bot added the stale label Mar 13, 2024
@MeLlamoPablo
Copy link
Author

Solved conflicts. This PR is still relevant, bumping to avoid having it auto closed.

@stale stale bot removed the stale label Mar 20, 2024
Copy link

stale bot commented Apr 22, 2024

Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️

@stale stale bot added the stale label Apr 22, 2024
@stale stale bot removed the stale label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant