Skip to content

Commit a8baa66

Browse files
airoweclaude
andauthored
fix(selectors): refuse a zero-area press target instead of tapping its origin (callstack#3934)
A 0x0 node (SpringBoard keeps page-1 icons that way on page 2) passed normalizeRect and resolved to its origin, so `press` tapped there and reported success. resolveInteractionTouchPoint now answers `invalid` for a target with zero width or height, which surfaces as the existing target_bounds_invalid refusal with dispatched: 'no'. Closes callstack#3841 Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 69b9745 commit a8baa66

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

‎packages/selectors/src/interaction-touch-point.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,37 @@ test('keeps the exact center when there are no competing interactive descendants
115115
});
116116
});
117117

118+
test.each<{ name: string; rect: Rect }>([
119+
{ name: 'zero width and height', rect: { x: 0, y: 0, width: 0, height: 0 } },
120+
{ name: 'zero width', rect: { x: 40, y: 120, width: 0, height: 60 } },
121+
{ name: 'zero height', rect: { x: 40, y: 120, width: 60, height: 0 } },
122+
])('refuses a $name target instead of resolving its origin', ({ rect }) => {
123+
const nodes = makeSnapshotState([
124+
{ index: 0, depth: 0, type: 'Icon', label: 'Clock', rect, hittable: false },
125+
]).nodes;
126+
127+
assert.deepEqual(resolveInteractionTouchPoint(nodes, nodes[0]!), { kind: 'invalid' });
128+
});
129+
130+
test('still resolves the smallest positive-area target', () => {
131+
const nodes = makeSnapshotState([
132+
{
133+
index: 0,
134+
depth: 0,
135+
type: 'Button',
136+
label: 'Dot',
137+
rect: { x: 40, y: 120, width: 1, height: 1 },
138+
hittable: true,
139+
},
140+
]).nodes;
141+
142+
assert.deepEqual(resolveInteractionTouchPoint(nodes, nodes[0]!), {
143+
kind: 'resolved',
144+
point: { x: 41, y: 121 },
145+
strategy: 'center',
146+
});
147+
});
148+
118149
test('keeps a parent-owned center in a thin row when a child is safely off to the side', () => {
119150
const nodes = makeSnapshotState([
120151
{

‎packages/selectors/src/interaction-touch-point.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function resolveInteractionTouchPoint(
3535
): InteractionTouchPointResolution {
3636
const targetRect = normalizeRect(node.rect);
3737
const center = resolveRectCenter(targetRect ?? undefined);
38-
if (!targetRect || !center) return { kind: 'invalid' };
38+
if (!targetRect || !center || !hasArea(targetRect)) return { kind: 'invalid' };
3939

4040
const competitors = collectInteractiveDescendantRects(nodes, node, targetRect);
4141
if (competitors.length === 0) {
@@ -59,6 +59,10 @@ export function resolveInteractionTouchPoint(
5959
return { kind: 'resolved', point, strategy: 'parent-owned' };
6060
}
6161

62+
function hasArea(rect: Rect): boolean {
63+
return rect.width > 0 && rect.height > 0;
64+
}
65+
6266
function collectInteractiveDescendantRects(
6367
nodes: readonly SnapshotNode[],
6468
node: SnapshotNode,

‎src/commands/interaction/runtime/resolution-touch-point.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,45 @@ test('runtime ref and selector paths dispatch the same parent-owned post point',
7979
assert.ok(refCalls[0]!.y < 292);
8080
assert.notDeepEqual(refCalls[0], { x: 201, y: 440 });
8181
});
82+
83+
test('runtime press refuses a selector match with a zero-area rect and dispatches no tap', async () => {
84+
const taps: Point[] = [];
85+
// SpringBoard page 2 keeps page-1 icons in the tree as 0x0 rects at the origin.
86+
const snapshot = makeSnapshotState([
87+
{
88+
index: 0,
89+
depth: 0,
90+
type: 'Application',
91+
label: 'SpringBoard',
92+
rect: { x: 0, y: 0, width: 402, height: 874 },
93+
hittable: true,
94+
},
95+
{
96+
index: 1,
97+
depth: 1,
98+
parentIndex: 0,
99+
type: 'Icon',
100+
label: 'Clock',
101+
rect: { x: 0, y: 0, width: 0, height: 0 },
102+
hittable: false,
103+
},
104+
]);
105+
const device = createInteractionDevice(snapshot, {
106+
tap: async (_context, point) => {
107+
taps.push(point);
108+
return { ok: true };
109+
},
110+
});
111+
112+
await assert.rejects(
113+
() => device.interactions.press(selector('label="Clock"'), { session: 'default' }),
114+
(error: unknown) => {
115+
const details = (error as { details?: Record<string, unknown> }).details;
116+
assert.equal((error as { code?: string }).code, 'COMMAND_FAILED');
117+
assert.equal(details?.reason, 'target_bounds_invalid');
118+
assert.equal(details?.dispatched, 'no');
119+
return true;
120+
},
121+
);
122+
assert.deepEqual(taps, []);
123+
});

0 commit comments

Comments
 (0)