Fix <SaveButton> form dirty status check#10997
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Fix SaveButton dirty state detection to align with react-hook-form ≥ 7.53.x where dirtyFields includes keys with false values.
- Replace naive key-length check with a recursive hasDirtyFields function.
- Add a ComplexForm Storybook story and a corresponding test to validate behavior with nested/array fields.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/ra-ui-materialui/src/button/SaveButton.tsx | Introduces hasDirtyFields to properly compute isDirty from dirtyFields, and uses lodash isEmpty for array-item handling. |
| packages/ra-ui-materialui/src/button/SaveButton.stories.tsx | Adds ComplexForm story to reproduce and visualize dirty state in complex forms (arrays of objects). |
| packages/ra-ui-materialui/src/button/SaveButton.spec.tsx | Adds a test to ensure SaveButton enables/disables correctly with nested/array fields and updates a test title for clarity. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
slax57
reviewed
Oct 20, 2025
slax57
requested changes
Oct 22, 2025
Merged
slax57
approved these changes
Oct 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In react-hook-form versions greater than
7.53.0(only tested7.53.2), fields that are not dirty are still present in thedirtyFieldsstate but with afalsevalue. However, our current dirty check in<SaveButton>only check whether thedirtyFieldsstate has object keys.Solution
Actually check whether any of the
dirtyFieldsstate keys have atruevalue to determine the dirty status.How To Test
<SaveButton>disabled state after/before saving.Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a featureAlso, please make sure to read the contributing guidelines.