diff --git a/yes.js b/yes.js index 4a02419..0d746b2 100644 --- a/yes.js +++ b/yes.js @@ -11,6 +11,22 @@ export class RasterizedYES { constructor() { this.rasterCanvas = document.getElementById('rasterCanvas'); this.lineCanvas = document.getElementById('lineCanvas'); + + // The Rust side only constructs this once it's confirmed (via a + // NodeRef) that the canvas is mounted, but that guard has shown + // a real gap on fast client-side re-navigation back to `/` - + // this is the actual failure point, so it gets its own defense + // rather than depending on getting that timing exactly right + // from the other side of the wasm boundary. Leaving the + // instance otherwise-inert (no crash, no animation) rather than + // throwing mid-render - `stop()` already tolerates a partially + // (non-)initialized instance. + if (!this.rasterCanvas || !this.lineCanvas) { + console.warn('RasterizedYES: canvas not in DOM yet, skipping'); + this.destroyed = true; + return; + } + this.rasterCtx = this.rasterCanvas.getContext('2d'); this.lineCtx = this.lineCanvas.getContext('2d');