fix(core): honour localChangesBackup: false - #945
Merged
fgatti675 merged 1 commit intoJul 31, 2026
Conversation
`EntityCollection.localChangesBackup` documents three states, but `false` could not be used by consumers. `getLocalChangesBackup` tested the value for falsiness, so `false` took the same branch as `undefined` and always resolved to the `"manual_apply"` default. The declared type admits three states while the implementation could only ever return two, meaning a collection that opted out still got the restore prompt. Separately, the backup write in `EntityForm.onValuesChangeDeferred` never read the flag, so `saveEntityToCache` persisted to `localStorage` on every deferred change regardless. Since the documented meaning of `false` is that local changes "will not be backed up", fixing the check alone would have stopped cached drafts being applied while still writing them on every keystroke. `localChangesBackup` is already in scope, so the write is now gated on it. Adds unit tests covering all three states plus the default. The `false` case fails before this change with `Expected: false, Received: "manual_apply"`. Fixes firecmsco#944 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes EntityCollection.localChangesBackup so that the documented false state is actually respected by the runtime behavior in core form handling, and adds regression tests to prevent the issue from reappearing.
Changes:
- Fix
getLocalChangesBackupsofalseis no longer treated as “unset” (defaulting only when the value isundefined). - Gate draft persistence to local storage in
EntityFormso no cache writes occur whenlocalChangesBackup === false. - Add Jest coverage for all supported
localChangesBackupstates plus the default.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/firecms_core/src/util/collections.ts | Makes false reachable by defaulting only on undefined. |
| packages/firecms_core/src/util/tests/collections.test.ts | Adds regression tests covering default, both string modes, and false. |
| packages/firecms_core/src/form/EntityForm.tsx | Prevents saveEntityToCache writes when backups are explicitly disabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #944.
EntityCollection.localChangesBackupdocuments three states, butfalsecould not actually be used by consumers. Two changes, both one-liners.1.
falsewas unreachablepackages/firecms_core/src/util/collections.tsfalseis falsy, so it took the same branch asundefinedand always resolved to the"manual_apply"default. The declared type"manual_apply" | "auto_apply" | falseadmits three states while the implementation could only ever return two, sobuildCollection({ localChangesBackup: false })silently behaved as"manual_apply"and still showed the restore prompt it opted out of.2. The backup write was never gated by the flag
packages/firecms_core/src/form/EntityForm.tsxonValuesChangeDeferredcalledsaveEntityToCacheon every deferred change without consulting the flag. Since the documented meaning offalseis that local changes "will not be backed up", and backing up is exactly what that call does, fixing only the check above would disable applying cached drafts while still writing them tolocalStorageon every keystroke.localChangesBackupis already in scope (declared a few lines above), so no extra plumbing is needed.This also matters for collections holding large or sensitive field values, where opting out of persisting form content to
localStorageis the point.Behaviour with
localChangesBackup: falselocalStorageLocalChangesMenuValues other than
falseare unaffected, and an unset flag still defaults to"manual_apply".Tests
Adds
packages/firecms_core/src/util/__tests__/collections.test.tscovering all three states plus the default. Thefalsecase is a genuine regression test — reverting thecollections.tschange makes it fail with:npx jestinpackages/firecms_coregoes from 230 to 234 passing tests. The 4 failing suites (VirtualTable.performance,date_conversion,navigation,validation— 3 failing tests) fail identically on an unmodifiedmaincheckout and are unrelated to this change.Notes
There is currently no supported workaround:
getLocalChangesBackupis the only symbol exported from this area, whileclearEntityCacheandremoveEntityFromCacheare internal, so consumers can neither opt out nor clear the cache through the public API.🤖 Generated with Claude Code