Skip to content

fix(addons): cancel pending saves when local storage is disabled - #1836

Open
pcbeingused33 wants to merge 1 commit into
formkit:masterfrom
pcbeingused33:fix/local-storage-cancel-pending-save
Open

pcbeingused33 wants to merge 1 commit into
formkit:masterfrom
pcbeingused33:fix/local-storage-cancel-pending-save

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

No linked issue.

Disabling local storage (for example, unchecking a "remember my answers" control field) removes the saved draft, but a debounce timer scheduled by an edit made just before can still fire and write the draft back, so the form data stays in localStorage for maxAge even though the user opted out. Cancel the pending timer before removing the key when the control field or the use-local-storage prop disables saving.

The regression test saves an initial draft, edits the form again, and turns the control off before the debounce expires. It checks that the key is removed immediately and stays absent after the timer would have fired.

pnpm vitest run packages/addons/__tests__/localStorage.spec.ts (after pnpm build all): the new test fails on master (the key is written back once the timer fires) and passes with this change; the other tests in the file still pass.

Prepared with AI assistance.

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.

1 participant