diff --git a/src/overlays/worldOverlay.js b/src/overlays/worldOverlay.js index 39a3f626cc..bb0d2d33f1 100644 --- a/src/overlays/worldOverlay.js +++ b/src/overlays/worldOverlay.js @@ -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; } diff --git a/src/overlays/worldOverlay.test.mjs b/src/overlays/worldOverlay.test.mjs index 4b27e73aeb..d64d065978 100644 --- a/src/overlays/worldOverlay.test.mjs +++ b/src/overlays/worldOverlay.test.mjs @@ -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);