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

Valibot infinate loop in resolver #655

Conversation

richardvanbergen
Copy link
Contributor

@richardvanbergen richardvanbergen commented Dec 18, 2023

Describe the bug
In recent versions of valibot they've introduced a variant method. This method does not set a path value in the issues array. Because of the way the valibotResolver loops over the issues returned from valibot, this can cause an infinite loop.

To Reproduce

  1. Using the following schema:
const numberSchema = object({
  type: literal("number")
})

const stringSchema = object({
  type: literal("string")
})

const typeSchema = variant("type", [numberSchema, stringSchema])
  1. Try to call the valibot resolver.
const data = {
  type: undefined
}

await valibotResolver(typeSchema, undefined, {
  mode: 'sync',
})(data, undefined, {
  fields,
  shouldUseNativeValidation,
});
  1. Browser or test runner freezes.

Additional context

I've included tests in this PR. If you wish to demonstrate the issue you can revert the changes I made to valibot.ts.

Because there's no path returned from valibot we can't add the error to the resolver. I've requested a change in valibot to address this and the author seems to agree. This PR simply fixes the infinite loop and I will submit a second once the other issue has been addressed to update the dependency to the fixed version.

I've tried to follow the contributing guidelines as best as I can. It seems as they're out of date or were copied from somewhere else the following commands listed aren't in this repo as far as I can tell:

  • tsd
  • e2e
  • start
  • api-extractor

New version includes new methods. In particular for this branch `variant()` which can cause an infinite loop
Copy link
Member

@jorisre jorisre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution :)

@jorisre jorisre merged commit 6f1b139 into react-hook-form:master Dec 26, 2023
4 checks passed
Copy link
Contributor

🎉 This PR is included in version 3.3.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants