fix(map): one persistent canvas renderer for critical-news pins (per-pin leak + only-last-pin-clickable) #66

Merged
sirius merged 1 commit from wt/t_40da439a into master 2026-11-20 04:31:32 +00:00
Owner

Bug (pre-existing, found during T2 / PR #65 verification; user-reported as "selecting Critical News makes the site reload")

loadNewsPins() called renderer: pointCanvas() INSIDE the per-pin .map() callback:

  • One full-viewport canvas per critical pin (5 pins = 5 canvases per refresh, ~19 MB each at retina 2x). Leaflet keeps empty renderers mounted, so nothing was ever removed on refresh → unbounded growth. Measured on pristine fe2b5df: 5 canvases after enable, 35 after 6 pan/zoom refreshes (+5/refresh), 145 after ~24 refreshes. This is the live hang/reload the user sees: unbounded full-viewport canvases stall the GPU/main thread (orchestrator live repro: CDP eval timed out repeatedly after clicking lp-news-on, no JS exception — a wedge, not a crash).
  • Only the LAST pin was clickable: all canvases are pointer-events:auto at z100; the topmost (last pin's) canvas ate every click. Measured on pristine master: Kyiv (first) and Tampa (2nd) clicks → nothing; Kherson (last) → popup.

Fix (app/static/index.html only, +19/−2)

  1. Hoist one persistent L.canvas({padding:0.5}) into module-level newsRenderer (mirrors T2's articlesRenderer pattern), shared by all pins, reused across refreshes. L.Canvas hit-tests every drawn path → all pins clickable. Removed on toggle-off → 0 canvases when the layer is off.
  2. Leaflet 1.9.4 race guard (4 lines + comment): a moveend-driven _updatePaths() calls _redraw() directly, which nulls _redrawRequest WITHOUT cancelling an already-pending animation frame. If the renderer is removed before that orphaned frame fires (toggle-off), _redraw crashes on the deleted 2d context (Cannot read properties of undefined (reading 'clearRect') — observed once during stress verification, 12 errors). The guard no-ops redraws on detached renderers; live renderers are byte-identical in behavior. Same class of targeted library workaround as T2's .leaflet-heatmap-layer { pointer-events: none; }.

Popup content, cyan styling, /api/news/map consumption, toggle/count/HUD behavior otherwise unchanged.

Real-browser verification (local mock: 5-pin /api/news/map + T2's 1398-row /api/news/blips fixture, Leaflet 1.9.4 vendored)

Before (pristine fe2b5df, same mock): Kyiv/Tampa clicks dead, Kherson clickable; canvases 5 → 35 after 6 refreshes → 145 after the full session.

After (this branch):

  • ✅ EVERY pin (Kyiv, Tampa, Geneva, Beirut, Kherson) opens its correct popup on real coordinate clicks — Article Blips OFF (world z2) and ON (per-pin z9), 5/5 both modes.
  • ✅ Canvas count flat at 1 across 12 pan/zoom refreshes (12 real /api/news/map refetches logged); same renderer instance reused; still 1 with blips ON (6 more refreshes).
  • ✅ Toggle OFF → 0 canvases, renderer/group null, count 0, HUD chip off; ON → 1 canvas, 5 pins, count/HUD 5.
  • ✅ User-complaint acceptance: 6 off/on toggle cycles — every CDP eval returned in 1–2 ms (no wedge), boot sentinel intact, performance.navigation entries = 1, type navigate (no reload/navigation). Plus 4 toggles fired immediately after setView (race stress): zero errors.
  • ✅ Article blips still clickable above the canvas (svg z200, pe:none root) — article popup opens; both layers coexist.
  • ✅ Counts/HUD unchanged (NEWS 5, ARTICLES match fixture bbox); popup HTML byte-identical structure.
  • ✅ Zero console errors across the full final session (error + unhandledrejection + console.error collectors).
  • ✅ Screenshots: region view (pins + clusters + HUD) and Kyiv popup open with blips ON — attached to kanban card t_40da439a.

Note: at z8 a 3-blip cluster icon can sit exactly over a pin center (marker pane z600 > canvas z100) and intercept the click — pre-existing T2 clustering behavior, unrelated to this fix; at z9 and world view all pin centers are clear.

Kanban: t_40da439a. Merge-on-green; static ships in the app image (Dockerfile COPY app/).

## Bug (pre-existing, found during T2 / PR #65 verification; user-reported as "selecting Critical News makes the site reload") `loadNewsPins()` called `renderer: pointCanvas()` INSIDE the per-pin `.map()` callback: - **One full-viewport canvas per critical pin** (5 pins = 5 canvases per refresh, ~19 MB each at retina 2x). Leaflet keeps empty renderers mounted, so nothing was ever removed on refresh → unbounded growth. Measured on pristine `fe2b5df`: **5 canvases after enable, 35 after 6 pan/zoom refreshes (+5/refresh), 145 after ~24 refreshes**. This is the live hang/reload the user sees: unbounded full-viewport canvases stall the GPU/main thread (orchestrator live repro: CDP eval timed out repeatedly after clicking `lp-news-on`, no JS exception — a wedge, not a crash). - **Only the LAST pin was clickable**: all canvases are `pointer-events:auto` at z100; the topmost (last pin's) canvas ate every click. Measured on pristine master: Kyiv (first) and Tampa (2nd) clicks → nothing; Kherson (last) → popup. ## Fix (app/static/index.html only, +19/−2) 1. **Hoist one persistent `L.canvas({padding:0.5})`** into module-level `newsRenderer` (mirrors T2's `articlesRenderer` pattern), shared by all pins, reused across refreshes. `L.Canvas` hit-tests every drawn path → **all pins clickable**. Removed on toggle-off → 0 canvases when the layer is off. 2. **Leaflet 1.9.4 race guard** (4 lines + comment): a moveend-driven `_updatePaths()` calls `_redraw()` directly, which nulls `_redrawRequest` WITHOUT cancelling an already-pending animation frame. If the renderer is removed before that orphaned frame fires (toggle-off), `_redraw` crashes on the deleted 2d context (`Cannot read properties of undefined (reading 'clearRect')` — observed once during stress verification, 12 errors). The guard no-ops redraws on detached renderers; live renderers are byte-identical in behavior. Same class of targeted library workaround as T2's `.leaflet-heatmap-layer { pointer-events: none; }`. Popup content, cyan styling, `/api/news/map` consumption, toggle/count/HUD behavior otherwise unchanged. ## Real-browser verification (local mock: 5-pin `/api/news/map` + T2's 1398-row `/api/news/blips` fixture, Leaflet 1.9.4 vendored) **Before (pristine fe2b5df, same mock):** Kyiv/Tampa clicks dead, Kherson clickable; canvases 5 → 35 after 6 refreshes → 145 after the full session. **After (this branch):** - ✅ EVERY pin (Kyiv, Tampa, Geneva, Beirut, Kherson) opens its correct popup on real coordinate clicks — **Article Blips OFF (world z2) and ON (per-pin z9)**, 5/5 both modes. - ✅ Canvas count **flat at 1 across 12 pan/zoom refreshes** (12 real `/api/news/map` refetches logged); same renderer instance reused; still 1 with blips ON (6 more refreshes). - ✅ Toggle OFF → 0 canvases, renderer/group null, count 0, HUD chip off; ON → 1 canvas, 5 pins, count/HUD 5. - ✅ **User-complaint acceptance: 6 off/on toggle cycles — every CDP eval returned in 1–2 ms (no wedge), boot sentinel intact, `performance.navigation` entries = 1, type `navigate` (no reload/navigation)**. Plus 4 toggles fired immediately after `setView` (race stress): zero errors. - ✅ Article blips still clickable above the canvas (svg z200, pe:none root) — article popup opens; both layers coexist. - ✅ Counts/HUD unchanged (NEWS 5, ARTICLES match fixture bbox); popup HTML byte-identical structure. - ✅ **Zero console errors** across the full final session (error + unhandledrejection + console.error collectors). - ✅ Screenshots: region view (pins + clusters + HUD) and Kyiv popup open with blips ON — attached to kanban card t_40da439a. Note: at z8 a 3-blip cluster icon can sit exactly over a pin center (marker pane z600 > canvas z100) and intercept the click — pre-existing T2 clustering behavior, unrelated to this fix; at z9 and world view all pin centers are clear. Kanban: t_40da439a. Merge-on-green; static ships in the app image (Dockerfile COPY app/).
loadNewsPins() called renderer: pointCanvas() INSIDE the per-pin .map(),
giving every critical pin its own full-viewport L.canvas (~19 MB each at
retina 2x). Renderers were never removed on refresh (Leaflet keeps empty
renderers mounted), so canvases grew without bound (35 after 6 refreshes
measured) and stacked pointer-events:auto siblings at z100 meant only the
LAST pin's canvas received clicks — Kyiv (first) was dead, Kherson (last)
worked. This is the user-reported 'selecting Critical News reloads the
site': unbounded full-viewport canvases stall the GPU/main thread.

Fix (mirrors T2's articlesRenderer pattern):
- hoist one persistent L.canvas({padding:0.5}) into module-level
  newsRenderer, shared by all pins and reused across refreshes; L.Canvas
  hit-tests every drawn path so ALL pins are clickable
- remove the renderer on toggle-off (0 canvases when layer off)
- guard L.Canvas.prototype._redraw against detached renderers: Leaflet
  1.9.4's moveend-driven _updatePaths() calls _redraw() directly, nulling
  _redrawRequest without cancelling a pending animation frame; removing
  the renderer before that orphaned frame fires crashes on the deleted
  2d context ('clearRect of undefined'). No-op when detached, unchanged
  when live.

Verified in real browser against local mock of /api/news/map (5 pins) +
/api/news/blips (1398-row T2 fixture):
- all 5 pins open their popups on click, Article Blips ON and OFF
- canvas count flat at 1 across 12 pan/zoom refreshes (was +5/refresh);
  0 when toggled off, 1 when back on
- 6 toggle off/on cycles: every CDP eval 1-2 ms, no navigation/reload
  (boot sentinel + navigation entries unchanged), counts/HUD 0<->5
- 4 toggles mid-map-motion (race stress): zero errors
- article blips still clickable above the canvas (svg z200 pe:none)
- popup content, cyan styling, counts/HUD byte-identical; zero console
  errors across the full session

app/static/index.html only, +19/-2.
sirius merged commit a268eefb84 into master 2026-11-20 04:31:32 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/osint-dashboard!66
No description provided.