fix: read refs inside setTimeout to prevent stale closure in debounced save#623
Open
hobostay wants to merge 1 commit intoheygen-com:mainfrom
Open
fix: read refs inside setTimeout to prevent stale closure in debounced save#623hobostay wants to merge 1 commit intoheygen-com:mainfrom
hobostay wants to merge 1 commit intoheygen-com:mainfrom
Conversation
…d save The debounced save in handleContentChange captured projectId and filePath from refs at scheduling time (outside setTimeout). If the user switched files within the 600ms debounce window, the save would write the new content to the previous file path. Move the ref reads inside the setTimeout callback so the save always uses the current project ID and file path at the time the save actually fires. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jrusso1020
approved these changes
May 5, 2026
Collaborator
jrusso1020
left a comment
There was a problem hiding this comment.
Verified the stale-closure bug at App.tsx:639–650: pid and path are captured at scheduling time, so a file switch inside the 600ms debounce window writes content into the previous file. Reading from projectIdRef/editingPathRef inside the timeout fires fixes it; the early-return guard for missing values is also a correct safety net. LGTM.
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.
Summary
handleContentChangewhere the debounced save writes content to the wrong fileprojectIdandfilePathwere captured from refs at scheduling time; if the user switches files during the 600ms debounce window, the save writes to the previous fileDetails
Affected file:
packages/studio/src/App.tsx(lines 631-651)The
setTimeoutclosure capturedpidandpathfrom the outer scope at the time the timeout was scheduled. If the user edits file A, then switches to file B within 600ms, the debounced save would write file B's content to file A's path.The fix moves the ref reads inside the
setTimeoutcallback so they always reflect the current state at execution time.Test plan
🤖 Generated with Claude Code