-
-
Notifications
You must be signed in to change notification settings - Fork 862
fix: retry giveFocus on next animation frame for newly created blocks #3100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sawka
merged 3 commits into
wavetermdev:main
from
majiayu000:fix/issue-2926-block-focus-on-create
Mar 24, 2026
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f90d576
fix: retry giveFocus on next animation frame for newly created blocks
majiayu000 1d42fbc
fix: cancel pending rAF in setFocusTarget on cleanup and re-invocation
majiayu000 c89126e
fix: guard rAF retry in setFocusTarget with focus containment check
majiayu000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 46
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 94
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 91
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 91
🏁 Script executed:
# Check file size first wc -l ./frontend/app/block/block.tsxRepository: wavetermdev/waveterm
Length of output: 98
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 619
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 8613
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 103
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 1248
🏁 Script executed:
# Check the webview.tsx file size first wc -l ./frontend/app/view/webview/webview.tsxRepository: wavetermdev/waveterm
Length of output: 108
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 1439
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 453
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 3132
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 2003
🏁 Script executed:
Repository: wavetermdev/waveterm
Length of output: 1182
Double
giveFocus()invocation creates duplicate subscriptions in webview.The retry logic calls
giveFocus()twice: immediately (line 237) and in the RAF callback (line 244). The webview implementation has problematic side effects whenctrlShiftStateis true—it sets up aglobalStore.sub()subscription and returnsfalse. If the RAF callback fires whilectrlShiftStateis still true, a second subscription is created. Both subscriptions respond to the state change, causing duplicate unsubscribe calls, double focus() invocations, and potential memory leaks.Guard the RAF callback to skip the retry if focus is already on the block:
Suggested guard to prevent redundant retry
focusElemRef.current?.focus({ preventScroll: true }); pendingFocusRafRef.current = requestAnimationFrame(() => { pendingFocusRafRef.current = null; + if (focusedBlockId() === nodeModel.blockId) { + return; + } viewModel?.giveFocus?.(); }); - }, [viewModel]); + }, [viewModel, nodeModel.blockId]);🤖 Prompt for AI Agents