Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION issue: values data is reset after first render, when shouldUnregister…

  1. User

    ISSUE DESCRIPTION

    issue: values data is reset after first render, when shouldUnregister is provided

    Version Number

    7.71.2

    Codesandbox/Expo snack

    https://codesandbox.io/p/sandbox/blazing-dust-3225h9?file=%2Fsrc%2FApp.js

    Steps to reproduce

    1. Simply submit a form
    2. See error

    Expected behaviour

    It is possible to successfully submit a form, when data is provided via values, and shouldUnregister: true option is set

    What browsers are you seeing the problem on?

    Chrome

    Code of Conduct

    • I agree to follow this project's Code of Conduct

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /react-hook-form, current file: none) bash-$

  2. MiniMax Assistant

    Let me start by exploring the repository structure to understand what we're working with.

  3. MiniMax Assistant

    Let me look at the createFormControl.ts file to understand the code structure, particularly the parts that deal with shouldUnregister and values.

  4. MiniMax Assistant

    Let me look at the section around line 1677 to understand how _formValues is updated and the relationship with shouldUnregister.

  5. MiniMax Assistant

    Let me look at the start of the reset function and the related context.

  6. MiniMax Assistant

    Let me look at the useForm.ts to understand the initialization process.

  7. MiniMax Assistant

    Let me look at the codesandbox example to understand the issue better.

  8. MiniMax Assistant

    Let me look at the specific test for updating form values when values is provided.

  9. MiniMax Assistant

    Now let me reproduce the issue.

  10. MiniMax Assistant

    Let me look at the getValues function and the section that handles values initialization:

  11. MiniMax Assistant

    Let me look at the relevant section to understand how _formValues is initialized and used in the context of shouldUnregister.

  12. MiniMax Assistant

    Now let me create a reproduction script for the issue.

  13. MiniMax Assistant

    I've successfully reproduced the issue. The form is submitted with empty data. Let me look at the setValue function and how _formValues is updated.

  14. MiniMax Assistant

    Let me look at the git history to understand when this code was added.

  15. MiniMax Assistant

    Let me look at the most recent change to the _reset function.

  16. MiniMax Assistant

    Let me search for the original commit that introduced this code.

  17. MiniMax Assistant

    Let me look at the original implementation of this code:

  18. MiniMax Assistant

    Let me look at the relevant tests:

  19. MiniMax Assistant

    Now I have a clear understanding. The bug is in the _reset function in createFormControl.ts. When shouldUnregister: true and keepFieldsRef: true is used (which is the case when useForm({ values }) is called), the _formValues is reset to {} instead of being set to the new values.

    Let me look at the test cases related to this:

  20. MiniMax Assistant

    Now let me look at the current code more carefully and apply the fix:

  21. MiniMax Assistant

    Now let me apply the fix:

  22. MiniMax Assistant

    The sed command didn't work for multi-line. Let me use a Python script instead:

  23. MiniMax Assistant

    The fix is applied. Now let me run the reproduction test to see if it passes:

  24. MiniMax Assistant

    The reproduction test now passes. Let me also remove this test file since it's a temporary file:

  25. MiniMax Assistant

    Now let me run the existing tests to make sure I didn't break anything:

  26. MiniMax Assistant

    All useForm tests pass. Let me also run all the useForm tests:

  27. MiniMax Assistant

    All 451 tests pass. Let me also run all the tests in the repository:

  28. MiniMax Assistant

    All 1111 tests pass! Let me also test with TEST_ENV=server:

  29. MiniMax Assistant

    All tests pass. Now let me think about edge cases:

  30. MiniMax Assistant

    All edge case tests pass. Let me clean up the test file:

  31. MiniMax Assistant

    Now let me verify the fix again by looking at the change:

  32. MiniMax Assistant

    Let me also verify the issue with the original sandbox scenario again. Let me write a more comprehensive test:

  33. MiniMax Assistant

    The fix is working. Let me clean up the test file:

  34. MiniMax Assistant

    Now let me also think about whether the fix could break any other scenarios. Let me look at the existing tests for shouldUnregister:

  35. MiniMax Assistant

    Let me also run the tests with focus on shouldUnregister:

  36. MiniMax Assistant

    All shouldUnregister tests pass. Let me also look at the test for the watch test that was modified:

  37. MiniMax Assistant

    The test passes. Now let me think about a possible edge case - what about the case when keepFieldsRef: true is passed but shouldUnregister: false?

    Let me trace through:

    • _options.shouldUnregister is false
    • keepStateOptions.keepFieldsRef is true
    • _formValues = keepStateOptions.keepFieldsRef ? (cloneObject(values) as TFieldValues) : ...
    • Result: _formValues = cloneObject(values). This is the same as before the fix.

    And what about when keepFieldsRef: false is passed explicitly (by overriding in useForm props)?

    • keepStateOptions.keepFieldsRef is false
    • _formValues = _options.shouldUnregister ? ... : (cloneObject(values) as TFieldValues)
    • If shouldUnregister: true, then _formValues = keepStateOptions.keepDefaultValues ? (cloneObject(_defaultValues) as TFieldValues) : ({} as TFieldValues).
    • If shouldUnregister: false, then _formValues = cloneObject(values). This is the same as before.

    Now let me look at the watch test more carefully:

  38. MiniMax Assistant

    Let me check the watch implementation:

  39. MiniMax Assistant

    Let me check the git history of the watch test:

  40. MiniMax Assistant

    Let me run the specific test to see the actual output:

  41. MiniMax Assistant

    Let me add some debugging to understand the test:

  42. MiniMax Assistant

    Let me look at the watch subscription in the form:

  43. MiniMax Assistant

    Let me look at the useWatch more carefully:

  44. MiniMax Assistant

    Let me look at the _subscribe function:

  45. MiniMax Assistant

    Let me look at shouldRenderFormState:

  46. MiniMax Assistant

    Let me look at the register function to understand the input value:

  47. MiniMax Assistant

    Let me also check that the fix works for defaultValues with shouldUnregister:

  48. MiniMax Assistant

    All edge case tests pass. Let me clean up:

  49. MiniMax Assistant

    Now let me run all the tests one more time to make sure everything still passes:

  50. MiniMax Assistant

    Let me also verify the final state of the fix:

  51. MiniMax Assistant

    Let me also check the git status:

  52. MiniMax Assistant

    Let me run the tests one more time to confirm everything still works:

  53. MiniMax Assistant

    All 1111 tests pass. Let me also verify the diff once more:

  54. MiniMax Assistant

    Let me do a final review of the change:

  55. MiniMax Assistant

    The fix is complete. Let me address the checklist:

    Checklist Review:

    1. If an error was reported in the issue description, I have successfully reproduced it.

      • ✅ YES. I created a temporary test file that reproduced the issue: when useForm({ values, shouldUnregister: true }) is used and the form is submitted, the form data is empty {} instead of containing the values.
    2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.

      • ✅ YES. After applying the fix, the reproduction test passes - the form submits with the correct values.
    3. I have thought about edge cases and made sure my fix handles them as well.

      • ✅ YES. I tested the following edge cases:
        • The original issue: useForm({ values, shouldUnregister: true }) and submit
        • useForm({ values, shouldUnregister: true }) with nested values (e.g., nested.field)
        • useForm({ values, shouldUnregister: true }) with values that update via setState
        • useForm({ defaultValues, shouldUnregister: true }) and submit
        • useForm({ defaultValues, shouldUnregister: true }) and call reset() then submit
    4. I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.

      • ✅ YES. All 1111 tests in the repository pass with my fix applied.

    Summary of the fix:

    The bug was in _reset function in src/logic/createFormControl.ts. When shouldUnregister: true and the _reset function is called with keepFieldsRef: true (which is the case when useForm({ values }) is used), the _formValues was being reset to {} instead of being set to the new values. This meant the form data was empty when submitted.

    The fix adds a check for keepFieldsRef: true before the shouldUnregister check. When keepFieldsRef: true, the _formValues is set to the new values (cloned) regardless of whether shouldUnregister: true. This is because keepFieldsRef: true indicates that the values are being updated (typically via the useForm({ values }) prop), and the field references are being kept. In this case, the new values should be used.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.