From f6314884f7ebe03295d0a72f5f65555c042ffcfd Mon Sep 17 00:00:00 2001 From: manjunath22466 Date: Mon, 16 Nov 2026 21:13:32 +0530 Subject: [PATCH] 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. --- src/overlays/worldOverlay.js | 11 ++++++----- src/overlays/worldOverlay.test.mjs | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) 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);