fix(map): one persistent canvas renderer for critical-news pins (per-pin leak + only-last-pin-clickable) #66
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/t_40da439a"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug (pre-existing, found during T2 / PR #65 verification; user-reported as "selecting Critical News makes the site reload")
loadNewsPins()calledrenderer: pointCanvas()INSIDE the per-pin.map()callback: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 clickinglp-news-on, no JS exception — a wedge, not a crash).pointer-events:autoat 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)
L.canvas({padding:0.5})into module-levelnewsRenderer(mirrors T2'sarticlesRendererpattern), shared by all pins, reused across refreshes.L.Canvashit-tests every drawn path → all pins clickable. Removed on toggle-off → 0 canvases when the layer is off._updatePaths()calls_redraw()directly, which nulls_redrawRequestWITHOUT cancelling an already-pending animation frame. If the renderer is removed before that orphaned frame fires (toggle-off),_redrawcrashes 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/mapconsumption, toggle/count/HUD behavior otherwise unchanged.Real-browser verification (local mock: 5-pin
/api/news/map+ T2's 1398-row/api/news/blipsfixture, 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):
/api/news/maprefetches logged); same renderer instance reused; still 1 with blips ON (6 more refreshes).performance.navigationentries = 1, typenavigate(no reload/navigation). Plus 4 toggles fired immediately aftersetView(race stress): zero errors.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.