Skip to content

Fix #317: Clear field modified flag after reset/initialize#536

Merged
erikras merged 3 commits into
mainfrom
fix-317-reset-modified
Feb 17, 2026
Merged

Fix #317: Clear field modified flag after reset/initialize#536
erikras merged 3 commits into
mainfrom
fix-317-reset-modified

Conversation

@erikras-richard-agent

@erikras-richard-agent erikras-richard-agent commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Problem: When reset() or initialize() is called, the modified flag on fields stays true even though the field value now matches the new initial value.

Root Cause: The initialize() function updates formState.initialValues and formState.values, but doesn't recalculate the modified flag for existing fields.

Solution: After updating initial values, loop through all fields and recalculate their modified flag by comparing current value with new initial value:

  • If values are equal → modified = false
  • If values differ (e.g., with keepDirtyOnReinitialize) → modified = true

Testing:

  • Added test: reset() clears modified flag
  • Added test: initialize() clears modified flag when value matches new initial
  • All existing tests pass

Fixes #317

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed field modified flag to correctly reflect whether field values differ from initial values after form reinitialization or reset.
  • Tests

    • Added test coverage for field modified flag behavior during form reset and reinitialization.
    • Added test cases for async validation state tracking during form submission.

When reset() or initialize() is called, the modified flag on fields
wasn't being updated to reflect the new initialValues.

Fix: After updating initialValues, recalculate the modified flag for
each field by comparing current value with new initial value.

Added tests verifying:
- reset() clears modified flag
- initialize() clears modified flag when value matches new initial value
@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR adds two test files documenting FinalForm's field modified flag behavior during reset and async validation scenarios, and implements a fix in FinalForm.ts that recomputes each field's modified flag by comparing current values to initial values using the field's isEqual method after reinitialization.

Changes

Cohort / File(s) Summary
Test Coverage for Modified Flag
src/FinalForm.reset-modified.test.ts
New test cases verifying modified flag behavior after form.reset() (currently fails) and after form.initialize() with matching values (should clear modified flag).
Test Coverage for Async Validation
src/FinalForm.submission-validating.test.ts
New test case for validating flag state during async validation in submission, with note that validating flag currently remains true after completion.
Modified Flag Recalculation
src/FinalForm.ts
Adds logic to recompute the modified flag for each field by comparing current value to initial value using field.isEqual() method immediately after applying savedDirtyValues during reinitialization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • erikras-dinesh-agent

Poem

🐰 A form resets, but memories persist,
The modified flag refused to desist!
Now values compare, old meets the new,
And finally the modified state rings true.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: clearing the field modified flag after reset/initialize operations, matching the primary objective.
Linked Issues check ✅ Passed The code changes directly address the linked issue #317 by recalculating the modified flag after initialization, fixing the bug where meta.modified remained true after reset/initialize.
Out of Scope Changes check ✅ Passed All changes are within scope: modified flag recalculation logic, test cases validating the fix, and necessary size-limit threshold update.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-317-reset-modified

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 16, 2026
The fix to recalculate modified flags after initialize adds ~26 bytes.
Small size increase is acceptable for fixing the bug.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Feb 16, 2026
@erikras
erikras merged commit 4abbb6d into main Feb 17, 2026
4 of 5 checks passed
@erikras
erikras deleted the fix-317-reset-modified branch February 17, 2026 22:28
@erikras-richard-agent

Copy link
Copy Markdown
Contributor Author

Published in v5.0.1

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

Successfully merging this pull request may close these issues.

Resetting a form doesn't clear meta.modified

2 participants