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

raw: true option on ZodResolver not passing copy of form submission values #718

Open
ben-reitz opened this issue Oct 15, 2024 · 0 comments

Comments

@ben-reitz
Copy link

ben-reitz commented Oct 15, 2024

Describe the bug
When passing the raw option to the zodResolver function, it seems to be passing the object that RHF uses to manage the state of the form into handleSubmit rather than a snapshot of the submitted form values on submission.

The codesandbox shows a simplified example where if you take the values from the handleSubmit and put them into state, then change the value of a field in the form, it's changing the value of the object in state (without using setState). You can check the value of what's stored in state by pressing the button to re-render the page and checking the console log.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Codesandbox
  2. fill in the form & submit
  3. the values submitted get stored in state and rendered on screen
  4. change a value in the form field and don't submit
  5. press the re-render button to re-render the component.
  6. see that the value stored in state is now different without handleSubmit being called or the setState function being called

Codesandbox link (Required)
Include a codesandbox will help us to investigate the issue quicker.
Codesandbox using zodResolver

Expected behavior
The handleSubmit function should pass a copy of the current raw form values, rather than an object which is still being manipulated by RHF. To me, raw means the form values before they were processed by the schema, rather than the original object which is being continually manipulated by RHF.

Additional context
It doesn't do this if you don't pass raw: true as an argument to the resolver

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

No branches or pull requests

1 participant