Skip to content

Commit c747d0c

Browse files
committed
Skip restoreStepAnswer when only callback ref changed
1 parent 5371548 commit c747d0c

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

apps/code/src/renderer/components/action-selector/useActionSelectorState.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function isInteractiveElementInDifferentCell(
2828

2929
const activeCell = el.closest("[data-grid-cell]");
3030
const ownCell = containerRef.current?.closest("[data-grid-cell]");
31+
32+
// Outside a grid (single-task mode): block focus steal from any interactive element.
33+
// Inside a grid: only block when the interactive element is in a different cell.
3134
if (!activeCell || !ownCell) return true;
3235

3336
return activeCell !== ownCell;
@@ -72,6 +75,7 @@ export function useActionSelectorState({
7275
() => new Map(),
7376
);
7477
const containerRef = useRef<HTMLDivElement>(null);
78+
const prevActiveStepRef = useRef(currentStep);
7579

7680
const activeStep = internalStep;
7781
const hasSteps = steps !== undefined && steps.length > 1;
@@ -152,6 +156,8 @@ export function useActionSelectorState({
152156
);
153157

154158
useEffect(() => {
159+
if (activeStep === prevActiveStepRef.current) return;
160+
prevActiveStepRef.current = activeStep;
155161
restoreStepAnswer(activeStep, {
156162
autoFocus: !isInteractiveElementInDifferentCell(containerRef),
157163
});

0 commit comments

Comments
 (0)