Skip to content

Commit c89126e

Browse files
committed
fix: guard rAF retry in setFocusTarget with focus containment check
Skip the requestAnimationFrame retry of giveFocus() if focus has already moved outside the block, preventing unnecessary calls when the user has clicked elsewhere between scheduling and execution. Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 1d42fbc commit c89126e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

frontend/app/block/block.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => {
241241
focusElemRef.current?.focus({ preventScroll: true });
242242
pendingFocusRafRef.current = requestAnimationFrame(() => {
243243
pendingFocusRafRef.current = null;
244-
viewModel?.giveFocus?.();
244+
if (blockRef.current?.contains(document.activeElement)) {
245+
viewModel?.giveFocus?.();
246+
}
245247
});
246248
}, [viewModel]);
247249

0 commit comments

Comments
 (0)