fix(overlays): keep painted hit rectangles until the next paint

Every overlay change cleared the world overlay's hit rectangles at once, and
only the next paint rebuilt them. When one click subscriber published its
selection card, every later subscriber in the same click saw no overlay at
all, so the outcome of a click depended on listener order: a card or label
painted over another layer's item could lose to that item, or both acted.

Hit rectangles now stay what is painted on screen until the next paint
rebuilds them, so every subscriber reads the overlay the user clicked, and a
paint that draws nothing clears them.
This commit is contained in:
manjunath22466 committed 2026-11-16 21:13:32 +05:30
1 parent b2bc15e763
commit f6314884f7
2 files changed
+25 -5

No files matched your search

+6 -5
View File
@@ -884,7 +884,9 @@ function invalidateHost({ solve = true, layout = false } = {}) {
if (layout) _occludersDirty = true;
_canvasNeedsClear = true;
_paintRectCount = 0;
_hitRectCount = 0;
// Hit rectangles stay what is painted on screen until the next paint
// rebuilds them: every click subscriber reads the same overlay, even after
// an earlier one republishes entries in that click (a selection card).
_paintRectByKey.clear();
requestOverlayRender();
}
@@ -2783,10 +2785,9 @@ function drawWorldOverlay() {
resetFrameDiagnostics();
_solveDirty = false;
if (_canvasNeedsClear || _detectionSurfaceNeedsClear) clearCanvas();
if (_accessibilitySignature) {
_hitRectCount = 0;
syncAccessibleActions();
}
// Nothing is painted now, so nothing can be hit.
_hitRectCount = 0;
if (_accessibilitySignature) syncAccessibleActions();
syncPaintVisibility(false);
return;
}
+19
View File
@@ -1936,6 +1936,25 @@ test('paint rectangles publish from a pool and topmost interactive lookup wins',
env.cleanup();
});
test('hit rectangles stay what is painted until the next paint, through a republish in the same click', () => {
const env = installMockEnvironment();
initWorldOverlay(env.viewer);
setOverlayEntries('cards', [selectedEntry('card', { interactive: true })]);
env.postRender.raise();
assert.equal(hitTestWorldOverlay(200, 120)?.entryId, 'card');
// An earlier click subscriber publishes its own selection card: later
// subscribers in the same click still see what the user clicked on.
setOverlayEntries('other', [selectedEntry('elsewhere', { interactive: true })]);
clearOverlaySource('cards');
assert.equal(hitTestWorldOverlay(200, 120)?.entryId, 'card');
assert.equal(hitTestWorldOverlay(200, 120, { sourceId: 'cards' })?.entryId, 'card');
// The next paint shows the change, and the hit test follows it.
env.postRender.raise();
assert.equal(hitTestWorldOverlay(200, 120, { sourceId: 'cards' }), null);
assert.equal(hitTestWorldOverlay(200, 120)?.entryId, 'elsewhere');
env.cleanup();
});
test('CCTV stable frame slots gate ambient chrome and wire the exact host hit rectangle', () => {
const env = installMockEnvironment({ width: 500, height: 400, dpr: 1 });
initWorldOverlay(env.viewer);