[Bug] charts: WebGL marks stay blank after effects re-run (StrictMode, <Activity>)
Description
The WebGL marks keep their canvas across effect cycles but destroy its context on cleanup, so after a cleanup-and-rerun they never draw again.
In dotGL:
- The canvas is created once and kept in a ref (L112-L113).
- The unmount cleanup calls
loseContext(gl)(WEBGL_lose_context.loseContext(), webgl.ts) and nullsglRef, but notcanvasRef. - When the effects run again,
getWebGLContext(canvas)callscanvas.getContext('webgl')on the same canvas. That returns the same, now-lost context, so the draw effect returns early atgl.isContextLost(). registerContextLossHandlersis subscribed again, but a context lost throughWEBGL_lose_context.loseContext()is only restored whenrestoreContext()is called. Nothing calls it, sowebglcontextrestorednever fires and the redraw epoch never bumps.
This happens whenever React runs cleanups and then re-runs effects on the same instance: always in development under <StrictMode>, and in production when an <Activity> boundary is hidden and shown again.
The same pattern is in heatmapGL and streamGL. It is also in dotGLInteractive, whose canvases React renders, so they survive the cycle too.
Suggested fix: in the cleanup, also drop the canvas (canvasRef.current = null) so the next run creates a fresh one. For the React-rendered canvases in dotGLInteractive, either remount them with a key or call restoreContext() on the extension when the effects run again.
Reproduction
import {StrictMode} from 'react';
import {Chart, dotGL} from '@astryxdesign/charts';
const data = Array.from({length: 200}, (_, i) => ({x: i, y: Math.sin(i / 10)}));
export function App() {
return (
<StrictMode>
<Chart data={data} xKey="x" series={[dotGL('y', {color: '#2563eb'})]} />
</StrictMode>
);
}
- Expected: 200 points.
- Actual (development build): the plot area is empty. The same chart without
<StrictMode>draws.
Found by reading the code; I haven't run it in a browser.
Astryx Version
@astryxdesign/[email protected] (code checked on main at 16fe6a8)
Environment
Any browser with WebGL; React 19 <StrictMode> (development) or React 19.2 <Activity>
(Posted by Cindy's agent.)
Thanks for the precise report. A fix is up in #11816. dotGL, heatmapGL and streamGL now drop their canvas on cleanup, so a rerun mounts a fresh one with a live context. dotGLInteractive, whose canvases React keeps, restores the contexts its cleanup lost. New tests cover each mark under <StrictMode> and through an <Activity> hide and show. I'll note here when it lands.
(Posted by Cindy's agent.)
The fix has landed: #11816 merged to main as a4b8609. One change from my earlier note: dotGLInteractive now also creates fresh canvases each time its effect runs, instead of restoring the lost contexts, because Chromium refuses restoreContext() there. All four marks draw again after a <StrictMode> re-run and after an <Activity> hide and show, and tests cover each case.