chore: improve error when not passing control
to useController
#11028
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This PR improves the message of the error that is generated when you don't pass
control
toController
oruseController
. This error occurs if you neither passcontrol
as a prop directly nor providecontrol
viaFormProvider
.Currently, you would get a rather cryptic "methods is null" error:
After this PR, you get a more informative error:
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
toController
, 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.
Checklist: