bugfix: fix debounce for save draft functionality#545
Conversation
|
@cursor review |
There was a problem hiding this comment.
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(); | ||
| }, []); |
There was a problem hiding this comment.
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).
|
Oopsie I removed staging... |
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.
saveDraftusing refs to keep latest callback; cancel debounce on unmount.formatDraftDatato normalizedeadline(append timezone if missing).onChangeto trigger debounced save and managehideAutoSave/isDraftSavingstate.draftQueueAtomand related exports.draftQueueAtom; no functional changes to other initial atoms.Written by Cursor Bugbot for commit 639a770. This will update automatically on new commits. Configure here.