Skip to content

bugfix: fix debounce for save draft functionality#545

Open
mar4enkom wants to merge 1 commit into
stagingfrom
logout-infinite-loading-issue
Open

bugfix: fix debounce for save draft functionality#545
mar4enkom wants to merge 1 commit into
stagingfrom
logout-infinite-loading-issue

Conversation

@mar4enkom
Copy link
Copy Markdown

@mar4enkom mar4enkom commented Oct 30, 2025

What does this PR do?

Where should the reviewer start?

How should this be manually tested?

Any background context you want to provide?

What are the relevant issues?

Screenshots (if appropriate)


Note

Refactors draft autosave to a debounced flow (no queue), normalizes deadline formatting, and removes the now-unused draftQueue atom and hydration.

  • Listing Builder – Autosave
    • Replace save-queue logic with a simple debounced saveDraft using refs to keep latest callback; cancel debounce on unmount.
    • Add formatDraftData to normalize deadline (append timezone if missing).
    • Update onChange to trigger debounced save and manage hideAutoSave/isDraftSaving state.
  • Atoms
    • Remove draftQueueAtom and related exports.
  • Provider
    • Stop hydrating removed draftQueueAtom; no functional changes to other initial atoms.

Written by Cursor Bugbot for commit 639a770. This will update automatically on new commits. Configure here.

@akorchyn
Copy link
Copy Markdown
Member

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

}, [processSaveQueue]);
debouncedRef.current = debounce(latestSaveDraftRef.current, 1000);
return () => debouncedRef.current?.cancel();
}, []);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Stale Function Breaks Debounce Updates

The debounced function captures the initial saveDraft function value instead of dynamically calling the latest version. When saveDraft recreates due to dependency changes (like isEditing, getValues, or saveDraftMutation), the debounced function continues calling the stale version with outdated closures. This breaks the debounce functionality as it won't use updated values. The pattern should wrap the ref call: debounce(() => latestSaveDraftRef.current(), 1000).

Fix in Cursor Fix in Web

@akorchyn akorchyn deleted the branch staging November 18, 2025 12:06
@akorchyn akorchyn closed this Nov 18, 2025
@akorchyn akorchyn reopened this Nov 18, 2025
@akorchyn
Copy link
Copy Markdown
Member

Oopsie I removed staging...

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.

2 participants