Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.5-35B-A3B· alibabaHugging 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. Qwen Assistant

    Let me start by exploring the repository structure to understand the codebase and then find the issue related to values data being reset after first render when shouldUnregister is provided.

  3. Qwen Assistant

    Let me explore the issue more. The issue is about values data being reset after first render when shouldUnregister is provided. Let me first search for relevant files and understand the codebase structure.

  4. Qwen Assistant

    The createFormControl.ts file looks like it might contain the core logic for form control. Let me also check the useForm.ts file since that's the main hook being used. Let me search for references to shouldUnregister and values in the codebase.

  5. Qwen Assistant

    Let me look at the useForm.ts file first since that's where the initial issue might be.

  6. Qwen Assistant

    Let me look at the createFormControl.ts file to understand how values are handled with shouldUnregister.

  7. Qwen Assistant

    Let me continue reading the createFormControl.ts file to find the _reset function and how it handles values with shouldUnregister.

  8. Qwen Assistant

    Let me look at the _resetDefaultValues and _reset functions more closely.

  9. Qwen Assistant

    Let me look at the _reset function implementation:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1615,1750p' src/logic/createFormControl.ts </tool_call>

  10. Qwen Assistant

    Let me try the sed command again to read the _reset function.

  11. Qwen Assistant

    Now let me look at the relevant section in useForm.ts more carefully. The issue seems to be in the useEffect that handles props.values. Let me trace the issue:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '110,135p' src/useForm.ts </tool_call>

  12. Qwen Assistant

    Let me read the useEffect section from useForm.ts that handles props.values more carefully.

  13. Qwen Assistant

    Let me see the section that handles props.values.

  14. Qwen Assistant

    Let me see more of the values effect:

  15. Qwen Assistant

    Now I understand the issue. Let me look at the _reset function to see what's happening when keepFieldsRef is used and shouldUnregister is true. Let me check that section again:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1650,1700p' src/logic/createFormControl.ts </tool_call>

  16. Qwen Assistant

    The sed command seems to not be working as expected. Let me try a different approach - I'll use grep to find the relevant section and then use the bash terminal to get the content.

  17. Qwen Assistant

    Looking at this code more carefully, I can see the issue now. The problem is in the _reset function in createFormControl.ts. When keepStateOptions.keepFieldsRef is true and shouldUnregister is true, the code does:

    if (keepStateOptions.keepFieldsRef) {
      for (const fieldName of _names.mount) {
        setValue(
          fieldName as FieldPath<TFieldValues>,
          get(values, fieldName),
        );
      }
    }
    
    _formValues = _options.shouldUnregister
      ? keepStateOptions.keepDefaultValues
        ? (cloneObject(_defaultValues) as TFieldValues)
        : ({} as TFieldValues)
      : (cloneObject(values) as TFieldValues);
    

    The problem is:

    1. When keepFieldsRef is true, it calls setValue for each mounted field with the value from values
    2. But then immediately after, it resets _formValues to either an empty object {} or _defaultValues (when keepDefaultValues is true), ignoring the values that were just set via setValue

    Let me look at how setValue works to understand the issue better:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "const setValue" src/logic/createFormControl.ts </tool_call>

  18. Qwen Assistant

    The grep command didn't work. Let me try another approach to search for the setValue function.

  19. Qwen Assistant

    I found where setValue is defined. Let me look at the setValue function.

  20. Qwen Assistant

    Let me also look at the _setValue function:

  21. Qwen Assistant

    Let me get the _setValue function implementation:

    <tool_call> <function=bash_terminal> <parameter=command> cat src/logic/createFormControl.ts | sed -n '864,930p' </tool_call>

  22. Qwen Assistant

    The grep command didn't work, let me try again with a different approach.

  23. Qwen Assistant

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "setFieldValue|setFieldValues" src/logic/createFormControl.ts </tool_call>

  24. Qwen Assistant

    Let me try a different approach to search the file.

  25. Qwen Assistant

    Now I see setFieldValue is defined at line 762. Let me read it:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '762,840p' src/logic/createFormControl.ts </tool_call>

  26. Qwen Assistant

    The sed command is not working. Let me try a different approach using head/tail to get specific lines from the file.

  27. Qwen Assistant

    Now I understand the issue better. When _reset is called with keepFieldsRef: true and shouldUnregister is true, the code:

    1. Iterates over _names.mount and calls setValue for each field
    2. But then immediately after, it overwrites _formValues with an empty object {} or _defaultValues

    This is the bug. When shouldUnregister is true and the form is registered with values prop, the _formValues is being reset to empty object {} even though values were just set via setValue.

    Let me look at the specific section in the _reset function that handles this:

    <tool_call> <function=bash_terminal> <parameter=command> head -1720 src/logic/createFormControl.ts | tail -60 </tool_call>

  28. Qwen Assistant

    The sed command is not working as expected. Let me try using awk or another method to get specific lines.

  29. Qwen Assistant

    Now I understand the issue better. Let me see more context around lines 1670-1690.

    <tool_call> <function=bash_terminal> <parameter=command> cat -n src/logic/createFormControl.ts | sed -n '1660,1695p' </tool_call>

  30. Qwen Assistant

    Let me try a different approach to get the lines.

  31. Qwen Assistant

    Now I can see the issue clearly! When keepStateOptions.keepFieldsRef is true and _options.shouldUnregister is true, the code:

    1. Sets values for each field using setValue (which updates _formValues internally)
    2. But then immediately overwrites _formValues with an empty object {} (when keepDefaultValues is false)

    The bug is at lines 1677-1681 where _formValues is reset incorrectly when shouldUnregister is true. When we're using keepFieldsRef: true, we want to preserve the values that were just set via setValue. The fix should be to not reset _formValues to an empty object when keepFieldsRef is true.

    Let me also check how the issue manifests - looking at the useEffect in useForm.ts:

    <tool_call> <function=bash_terminal> <parameter=command> awk 'NR>=150 && NR<=170' src/useForm.ts </tool_call>

  32. Qwen Assistant

    Let me try a different approach to read the file.

  33. Qwen Assistant

    I can see the issue now. When props.values changes, the code calls:

    control._reset(props.values, {
      keepFieldsRef: true,
      ...control._options.resetOptions,
    });
    

    The problem is that in the _reset function, when shouldUnregister is true and keepFieldsRef is true, the values that were just set via setValue are being overwritten with an empty object.

    Let me check if there are any tests related to this issue:

    <tool_call> <function=bash_terminal> <parameter=command> ls src/tests/useForm/ </tool_call>

  34. Qwen Assistant

    The command isn't executing properly. Let me try a simpler approach without using grep or sed.

  35. Qwen Assistant

    Let me search for tests related to values and shouldUnregister together.

  36. Qwen Assistant

    Let me look at test around line 1083 to see how values with shouldUnregister is tested:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1083,1150p' src/tests/useForm/reset.test.tsx </tool_call>

  37. Qwen Assistant

    The sed command is still having issues. Let me try a different approach - I'll use awk or head/tail commands to read specific sections of the file.

  38. Qwen Assistant

    Now let me search for tests related to values prop with shouldUnregister:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "props.values|values:" src/tests/useForm/reset.test.tsx | head -20 </tool_call>

  39. Qwen Assistant

    The grep is still having issues. Let me try a simpler approach by looking at the setValue test file to see if there's any test for the combination of values and shouldUnregister.

  40. Qwen Assistant

    Now let me understand the issue better. Based on my analysis:

    1. When useForm is called with values prop and shouldUnregister: true
    2. The useEffect at line 150-168 in useForm.ts calls control._reset(props.values, { keepFieldsRef: true, ... })
    3. In the _reset function (lines 1615-1700 in createFormControl.ts), when shouldUnregister is true:
      • It iterates over _names.mount and calls setValue for each field (which correctly sets the values)
      • But then it immediately overwrites _formValues with an empty object {} (line 1679-1681)
      • This causes the values to be lost after the reset

    The fix should be: when keepFieldsRef: true is used with shouldUnregister: true, we should preserve the values that were just set via setValue instead of resetting to an empty object.

    Let me first create a script to reproduce the issue. Let me now create a simple test to reproduce the issue:

    <tool_call> <function=bash_terminal> <parameter=command> cat src/tests/useForm/reset.test.tsx | grep -A 30 "should keep reset value for conditionally mounted controlled fields with shouldUnregister" </tool_call>

  41. Qwen Assistant

    Let me take a more direct approach. I'll examine the test file and then create the fix:

  42. Qwen Assistant

    Now I understand the issue. Let me look more closely at the _reset function to understand the fix needed:

  43. Qwen Assistant

    Now I can see the issue clearly. The problem is at lines 1677-1681:

    _formValues = _options.shouldUnregister
      ? keepStateOptions.keepDefaultValues
        ? (cloneObject(_defaultValues) as TFieldValues)
        : ({} as TFieldValues)
      : (cloneObject(values) as TFieldValues);
    

    When shouldUnregister is true and keepFieldsRef is true, the code first sets values via setValue (lines 1665-1669), but then it overwrites _formValues with an empty object {}. This is the bug.

    The fix should be: when keepFieldsRef is true and shouldUnregister is true, we should not reset _formValues to an empty object. Instead, we should either:

    1. Keep the values that were set via setValue, or
    2. Skip the _formValues reset entirely when keepFieldsRef is true

    Let me check the _setValue function to see how it updates _formValues:

    From earlier analysis, _setValue calls set(_formValues, name, cloneValue) to update the value. So when setValue is called, it does update _formValues. But then the reset overwrites it with an empty object.

    The fix should be to not reset _formValues when keepFieldsRef is true, since the values have already been set via setValue.

    Let me create the fix:

    <tool_call> <function=bash_terminal> <parameter=command> cat src/logic/createFormControl.ts | awk 'NR>=1675 && NR<=1685' </tool_call>

  44. Qwen Assistant

    The awk command is still not working as expected. Let me try using head/tail instead.

  45. Qwen Assistant

    Now I can see the exact lines. The issue is at lines 1681-1685 where _formValues is reset incorrectly. When keepStateOptions.keepFieldsRef is true, we have already set the values via setValue (lines 1665-1669), so we shouldn't overwrite _formValues with an empty object.

    The fix should be to check if keepFieldsRef is true before resetting _formValues. Let me look at the full context:

    <tool_call> <function=bash_terminal> <parameter=command> head -1690 src/logic/createFormControl.ts | tail -20 </tool_call>

  46. Qwen Assistant

    The bash command is not working properly. Let me try a simpler approach without using grep or sed, and just use basic bash commands.

  47. Qwen Assistant

    Now I can see the issue. The problem is that when keepStateOptions.keepFieldsRef is true and _options.shouldUnregister is true:

    1. The code calls setValue for each mounted field (which correctly sets values)
    2. But then it immediately overwrites _formValues with an empty object {} or _defaultValues

    The fix should be to preserve the values when keepFieldsRef is true. When keepFieldsRef is true, we have already set the values via setValue, so we shouldn't overwrite them.

    Let me check what happens when setValue is called with a value:

    From my earlier analysis, _setValue does:

    set(_formValues, name, cloneValue);
    

    So _formValues is correctly updated by setValue. The issue is that the code then overwrites it.

    The fix should be: when keepStateOptions.keepFieldsRef is true and _options.shouldUnregister is true, we should not reset _formValues. We can do this by:

    1. Not resetting _formValues when keepFieldsRef is true, OR
    2. Using cloneObject(values) instead of an empty object when keepFieldsRef is true

    Looking at the logic:

    • When keepFieldsRef is true, the values are set via setValue which updates _formValues
    • When keepFieldsRef is false, _fields is cleared and we should reset _formValues

    So the fix should be to only reset _formValues when keepFieldsRef is false. Let me implement the fix:

    <tool_call> <function=bash_terminal> <parameter=command> open --file src/logic/createFormControl.ts 1677 </tool_call>

  48. Qwen Assistant

    The open command is not working as expected. Let me try a different approach to edit the file directly.

  49. Qwen Assistant

    Python3 is not available. Let me try with python or node.

  50. Qwen Assistant

    The template literal escaping is causing issues. Let me try a different approach:

    <tool_call> <function=bash_terminal> <parameter=command> node -e "const fs = require('fs'); const content = fs.readFileSync('src/logic/createFormControl.ts', 'utf8'); const lines = content.split('\n'); for (let i = 1675; i < 1685; i++) { console.log((i+1) + ': ' + lines[i]); }" </tool_call>

  51. Qwen Assistant

    Let me try a different approach to read and edit the file:

  52. Qwen Assistant

    Now I can see the code clearly. The issue is at lines 1681-1685:

    _formValues = _options.shouldUnregister
      ? keepStateOptions.keepDefaultValues
        ? (cloneObject(_defaultValues) as TFieldValues)
        : ({} as TFieldValues)
      : (cloneObject(values) as TFieldValues);
    

    The fix should be: when keepStateOptions.keepFieldsRef is true, we should not reset _formValues to an empty object. Instead, we should preserve the values that were set via setValue.

    Looking at the logic more carefully:

    • When keepStateOptions.keepFieldsRef is true, we have already set the values via setValue (lines 1665-1669)
    • So when keepStateOptions.keepFieldsRef is true and _options.shouldUnregister is true, we should use cloneObject(values) instead of {} or _defaultValues

    The fix should be:

    _formValues = _options.shouldUnregister
      ? keepStateOptions.keepDefaultValues
        ? (cloneObject(_defaultValues) as TFieldValues)
        : (keepStateOptions.keepFieldsRef
            ? (cloneObject(values) as TFieldValues)
            : ({} as TFieldValues))
      : (cloneObject(values) as TFieldValues);
    

    Or more simply:

    _formValues = _options.shouldUnregister
      ? keepStateOptions.keepDefaultValues
        ? (cloneObject(_defaultValues) as TFieldValues)
        : (keepStateOptions.keepFieldsRef
            ? (cloneObject(values) as TFieldValues)
            : ({} as TFieldValues))
      : (cloneObject(values) as TFieldValues);
    

    Wait, looking at the code again, I think the issue is that when keepFieldsRef is true, the values are set via setValue which updates _formValues. But then the code overwrites _formValues with an empty object. The fix should be to not overwrite _formValues when keepFieldsRef is true.

    Actually, looking at the logic more carefully:

    1. When keepStateOptions.keepFieldsRef is true, the values are set via setValue which updates _formValues
    2. The subsequent assignment to _formValues overwrites these values

    So the fix should be to only assign _formValues when keepFieldsRef is false, or to use cloneObject(values) when keepFieldsRef is true.

    Let me think about this more carefully:

    • When shouldUnregister is true, the form fields are unregistered when they are unmounted
    • When shouldUnregister is false, the form fields are kept in _formValues even when unmounted
    • When keepFieldsRef is true, we want to keep the field references but reset the values
    • When keepFieldsRef is false, we want to reset both the field references and the values

    Actually, looking at the code again, I think the issue is that when shouldUnregister is true and keepFieldsRef is true, the values should be preserved. The fix should be to use cloneObject(values) instead of {} when keepFieldsRef is true.

    Let me implement the fix using the replace command:

    <tool_call> <function=bash_terminal> <parameter=command> cat src/logic/createFormControl.ts | head -1685 | tail -10 </tool_call>

  53. Qwen Assistant

    Let me try using the special commands to edit the file. The issue is in the _reset function where _formValues is being overwritten incorrectly. Let me first understand the exact lines I need to modify.

  54. Qwen Assistant

    I need to edit the file using the edit command. The issue is at lines 1681-1685 where _formValues is being reset incorrectly when shouldUnregister is true and keepFieldsRef is true. Let me use the edit command to fix this.

  55. Qwen Assistant

    The edit command seems to have created a duplicate. Let me fix this by restoring the file and trying again with the correct approach.

    <tool_call> <function=bash_terminal> <parameter=command> git checkout src/logic/createFormControl.ts </tool_call>

  56. Qwen Assistant

    The git checkout command wasn't executed. Let me try again.

  57. Qwen Assistant

    Good, I've restored the original file. Now let me try the edit command again with the correct line numbers and proper indentation. Let me first verify the exact lines to edit:

  58. Qwen Assistant

    The lines to edit are 1681-1685. I need to replace:

          _formValues = _options.shouldUnregister
            ? keepStateOptions.keepDefaultValues
              ? (cloneObject(_defaultValues) as TFieldValues)
              : ({} as TFieldValues)
            : (cloneObject(values) as TFieldValues);
    

    With:

          _formValues = _options.shouldUnregister
            ? keepStateOptions.keepDefaultValues
              ? (cloneObject(_defaultValues) as TFieldValues)
              : keepStateOptions.keepFieldsRef
                ? (cloneObject(values) as TFieldValues)
                : ({} as TFieldValues)
            : (cloneObject(values) as TFieldValues);
    

    Let me use the edit command again:

  59. Qwen Assistant

    The edit command created a duplicate. Let me restore the file again and try a different approach.

  60. Qwen Assistant

    I'll use the replace command instead, which might work better. I need to search for the specific text pattern and replace it.

  61. Qwen Assistant

    The command syntax is incorrect. Let me try a simpler approach using the replace command with proper quoting:

  62. Qwen Assistant

    The replace command worked but the formatting is now on a single line. Let me fix the formatting to be multi-line for better readability.

    <tool_call> <function=bash_terminal> <parameter=command> git checkout src/logic/createFormControl.ts </tool_call>

  63. Qwen Assistant

    The git checkout command is not being executed. Let me try again with the proper syntax.

  64. Qwen Assistant

    Now let me use the edit command with proper formatting:

  65. Qwen Assistant

    The fix is in place. Now let me verify that the existing tests pass:

  66. Qwen Assistant

    Let me try a different approach to run the tests:

    <tool_call> <function=bash_terminal> <parameter=command> npx jest src/tests/useForm/reset.test.tsx --no-coverage 2>&1 | head -150 </tool_call>

  67. Qwen Assistant

    The command didn't run. Let me try a simpler command to run the tests.

  68. Qwen Assistant

    The test is failing due to a configuration issue. Let me try running the tests using the project's configured test setup:

  69. Qwen Assistant

    Let me see if there's a specific test configuration file I can use:

    <tool_call> <function=bash_terminal> <parameter=command> cat scripts/jest/jest.config.js </tool_call>

  70. Qwen Assistant

    Let me check the jest config file:

  71. Qwen Assistant

    Let me run the test with the proper configuration using the test script from the project:

    <tool_call> <function=bash_terminal> <parameter=command> TEST_ENV=web npx jest src/tests/useForm/reset.test.tsx --config=scripts/jest/jest.config.js --no-coverage 2>&1 | tail -100 </tool_call>

  72. Qwen Assistant

    The command is still not executing. Let me try a simpler approach - just run npm test and wait for all tests to complete.

    Looking at the output from before, the tests were passing. Let me just run npm test and see if my changes break anything.

  73. Qwen Assistant

    All 39 tests in the reset.test.tsx file pass. Now let me also run the setValue tests and watch tests that might be related to the issue:

  74. Qwen Assistant

    All setValue tests pass. Let me also run the watch tests since the issue mentions values prop being reset after first render:

  75. Qwen Assistant

    All watch tests pass. Now let me run the complete test suite to make sure my changes don't break anything:

  76. Qwen Assistant

    All 1111 tests pass. Now let me create a test script to verify the fix for the specific issue mentioned in the bug report. The issue is that when values prop is provided and shouldUnregister: true is set, the values are reset after first render.

    Let me first check if there's already a test case for this specific scenario:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "values.*shouldUnregister|shouldUnregister.values" src/tests --include=".tsx" -r </tool_call>

  77. Qwen Assistant

    The grep command didn't work. Let me try a different approach to search for tests related to the issue.

  78. Qwen Assistant

    Let me check the useForm test file to see if there's a test for the issue:

    <tool_call> <function=bash_terminal> <parameter=command> grep -rn "props.values|values:" src/tests/useForm.test.tsx | head -30 </tool_call>

  79. Qwen Assistant

    Let me try a different approach to check the existing tests.

  80. Qwen Assistant

    I need to search more specifically for tests related to the values prop and shouldUnregister option combination. Let me try to find these tests.

  81. Qwen Assistant

    Now I see that there are tests related to form values. Let me check if there's any test specifically for the values prop with shouldUnregister:

    <tool_call> <function=bash_terminal> <parameter=command> cat src/tests/useForm.test.tsx | grep -B5 -A20 "should only update async form values" </tool_call>

  82. Qwen Assistant

    Let me try a different approach:

  83. Qwen Assistant

    Now let me look at the shouldUnregister section to see if there's a test for the values prop:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '227,290p' src/tests/useForm.test.tsx </tool_call>

  84. Qwen Assistant

    The sed command is not executing properly. Let me try a different approach to read the test file.

  85. Qwen Assistant

    I see tests for shouldUnregister but I don't see any tests specifically for the combination of values prop with shouldUnregister. Let me now check if my fix actually addresses the issue by creating a simple test case.

    Looking at the issue description, the problem is:

    1. When values prop is provided to useForm
    2. And shouldUnregister: true is set
    3. After form submission, the values are reset/empty

    Let me verify my understanding by looking at the fix I made:

    The issue was in the _reset function in createFormControl.ts. When keepFieldsRef: true is passed (which is the case when props.values changes), the code:

    1. Sets values for each field via setValue (which correctly updates _formValues)
    2. But then immediately overwrites _formValues with an empty object {} when shouldUnregister is true

    My fix adds a check for keepStateOptions.keepFieldsRef to preserve the values instead of resetting to an empty object.

    Let me now verify the fix is correct by looking at the modified code again:

    <tool_call> <function=bash_terminal> <parameter=command> head -1690 src/logic/createFormControl.ts | tail -20 </tool_call>

  86. Qwen Assistant

    Let me try the bash_terminal command instead:

  87. Qwen Assistant

    The fix is in place. Now let me verify the fix by running all tests again to make sure everything passes:

    <tool_call> <function=bash_terminal> <parameter=command> TEST_ENV=web npx jest --config=scripts/jest/jest.config.js --no-coverage 2>&1 | tail -20 </tool_call>

  88. Qwen Assistant

    Let me verify the tests are running correctly by checking the test output:

  89. Qwen Assistant

    All tests pass. Now let me also verify the fix by checking the diff to make sure my changes are correct:

    <tool_call> <function=bash_terminal> <parameter=command> git diff src/logic/createFormControl.ts </tool_call>

  90. Qwen Assistant

    The git diff command is not being executed. Let me try using the bash_terminal tool.

  91. Qwen Assistant

    The fix looks correct. Let me summarize the issue and the fix:

    Issue: When useForm is called with values prop and shouldUnregister: true, the values are reset after first render. This happens because:

    1. In useForm.ts, when props.values changes, the useEffect calls control._reset(props.values, { keepFieldsRef: true, ... })
    2. In createFormControl.ts, the _reset function:
      • First, it sets values for each field via setValue (lines 1665-1669)
      • But then it immediately overwrites _formValues with an empty object {} when shouldUnregister is true (line 1680)

    Fix: Added a check for keepStateOptions.keepFieldsRef before resetting _formValues to an empty object. When keepFieldsRef is true, we preserve the values that were just set via setValue instead of resetting to an empty object.

    The fix is minimal and targeted:

    • When shouldUnregister is true and keepFieldsRef is true, we now use cloneObject(values) instead of an empty object
    • This ensures that the values passed via the values prop are preserved after the reset

    Now let me verify that all tests pass one more time before submitting:

    <tool_call> <function=bash_terminal> <parameter=command> TEST_ENV=web npx jest --config=scripts/jest/jest.config.js --no-coverage 2>&1 | grep -E "PASS|FAIL|Test Suites|Tests:" </tool_call>

  92. Qwen Assistant

    Let me try running the tests properly using the bash_terminal tool.

  93. Qwen Assistant

    The tests are passing. Now let me also run the TypeScript compiler to make sure there are no type errors in my fix:

    <tool_call> <function=bash_terminal> <parameter=command> npx tsc --noEmit 2>&1 | head -50 </tool_call>

  94. Qwen Assistant

    The TypeScript compiler command is not executing. Let me try using the bash_terminal tool properly.

  95. Qwen Assistant

    The TypeScript compiler ran without any errors, which means my fix is type-safe.

    Now let me verify the fix is complete by reviewing the changes one more time and then submitting:

    <tool_call> <function=bash_terminal> <parameter=command> git diff src/logic/createFormControl.ts </tool_call>

  96. Qwen Assistant

    Let me try using the bash_terminal tool to see the git diff output.

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