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

fix Ensure useFormContext always returns a valid context #74

Merged

Conversation

minai621
Copy link
Contributor

Description

This pull request addresses the issue where the useFormContext function could potentially return undefined, leading to instability in the register function. Given that defaultInjectionKey is provided, this situation should not occur. The useFormContext function has been updated to cast the injected value directly to FormHandlerReturn<T>, ensuring that it is always a valid context.

Changes Made

  • Updated useFormContext to cast the injected value to FormHandlerReturn<T>, ensuring it is always valid.
  • Improved the stability of form context usage.

Issue

This pull request resolves issue #73.

Copy link

vercel bot commented Jun 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vue-form-handler ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2024 3:12pm

@dbssman
Copy link
Owner

dbssman commented Jun 13, 2024

Description

This pull request addresses the issue where the useFormContext function could potentially return undefined, leading to instability in the register function. Given that defaultInjectionKey is provided, this situation should not occur. The useFormContext function has been updated to cast the injected value directly to FormHandlerReturn<T>, ensuring that it is always a valid context.

Changes Made

  • Updated useFormContext to cast the injected value to FormHandlerReturn<T>, ensuring it is always valid.
  • Improved the stability of form context usage.

Issue

This pull request resolves issue #73.

The assumption that since defaultInjectionKey is provided this does not occur is not correct, since you could be using the defaultInjectionKey but adding a different one at top level or reverse.

In any case, I do think this provides value and is, in general a good idea, since having to cast it manually is quite annoying.

I will include this fix in the next release :) thank you for contributing!

@minai621
Copy link
Contributor Author

@dbssman
Thank you for your detailed review and for pointing out the potential issue with the defaultInjectionKey assumption. I appreciate your positive feedback and am glad to hear that the fix will be included in the next release. Thank you for the opportunity to contribute! If you prefer, feel free to close the PR.

@dbssman dbssman merged commit 589d2de into dbssman:master Jun 22, 2024
2 checks passed
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.

2 participants