quick fix for #2918 (refocus block after magnify button click)#2930
quick fix for #2918 (refocus block after magnify button click)#2930
Conversation
WalkthroughThe change modifies the magnify toggle handler in the blockframe header component to introduce a delayed refocus action. When magnification is toggled, the handler now calls Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying waveterm with
|
| Latest commit: |
d4ee5b4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://37a32f17.waveterm.pages.dev |
| Branch Preview URL: | https://sawka-fix-magnify-focus.waveterm.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/app/block/blockframe-header.tsx`:
- Around line 144-147: The toggleMagnify handler currently calls
nodeModel.toggleMagnify() then schedules refocusNode(blockId) with setTimeout
without tracking or clearing the timer; change it to store the timer id (e.g. a
ref like magnifyTimeoutRef) and clearTimeout before setting a new timer to
debounce rapid toggles, and also clear the timer in the component cleanup
(useEffect return or componentWillUnmount) to avoid invoking refocusNode after
unmount; update the toggleMagnify callback to clear previous magnifyTimeoutRef,
set a new timeout for refocusNode(blockId), and ensure cleanup logic clears that
timeout.
| toggleMagnify={() => { | ||
| nodeModel.toggleMagnify(); | ||
| setTimeout(() => refocusNode(blockId), 50); | ||
| }} |
There was a problem hiding this comment.
Avoid stray refocus after unmount or rapid toggles (Line 144–147).
The timeout isn’t cleared; repeated clicks or unmounts can queue multiple refocus calls and potentially jump focus to a closed block. Consider debouncing and cleaning up the timer.
🔧 Suggested fix with timeout tracking & cleanup
const HeaderEndIcons = React.memo(({ viewModel, nodeModel, blockId }: HeaderEndIconsProps) => {
+ const refocusTimerRef = React.useRef<number | null>(null);
const endIconButtons = util.useAtomValueSafe(viewModel?.endIconButtons);
const magnified = jotai.useAtomValue(nodeModel.isMagnified);
@@
+ React.useEffect(() => {
+ return () => {
+ if (refocusTimerRef.current != null) {
+ clearTimeout(refocusTimerRef.current);
+ }
+ };
+ }, []);
@@
- toggleMagnify={() => {
- nodeModel.toggleMagnify();
- setTimeout(() => refocusNode(blockId), 50);
- }}
+ toggleMagnify={() => {
+ nodeModel.toggleMagnify();
+ if (refocusTimerRef.current != null) {
+ clearTimeout(refocusTimerRef.current);
+ }
+ refocusTimerRef.current = window.setTimeout(() => refocusNode(blockId), 50);
+ }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/app/block/blockframe-header.tsx` around lines 144 - 147, The
toggleMagnify handler currently calls nodeModel.toggleMagnify() then schedules
refocusNode(blockId) with setTimeout without tracking or clearing the timer;
change it to store the timer id (e.g. a ref like magnifyTimeoutRef) and
clearTimeout before setting a new timer to debounce rapid toggles, and also
clear the timer in the component cleanup (useEffect return or
componentWillUnmount) to avoid invoking refocusNode after unmount; update the
toggleMagnify callback to clear previous magnifyTimeoutRef, set a new timeout
for refocusNode(blockId), and ensure cleanup logic clears that timeout.
Code Review SummaryStatus: 1 Issue Found (Outside Diff) | Recommendation: Address before merge Overview
Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (1 file)
Changes in Diff: The PR correctly fixes the focus issue for the magnify button by adding |
No description provided.