From edfba6bf64e6676bcf0553989b34a610dd711767 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 17 Jun 2026 12:57:41 -0400 Subject: [PATCH] fix(jbrowse-plugin-apollo): guard document access in GeneGlyph for worker context This module loads in jbrowse's RPC worker (all configured plugins load there unconditionally), where globalThis.document is undefined. The module-level canvas pattern setup assumed document always exists, just guarding the canvas.getContext result -- that worked while jbrowse's worker provided a stub document, but jbrowse removed that polyfill, so document.createElement now throws synchronously and crashes the whole plugin load via importScripts (surfaced by Chrome as a generic NetworkError, masking the real TypeError). Guard the document access itself instead; these patterns are main-thread-only rendering fills the worker never needs. --- .../src/LinearApolloSixFrameDisplay/glyphs/GeneGlyph.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/jbrowse-plugin-apollo/src/LinearApolloSixFrameDisplay/glyphs/GeneGlyph.ts b/packages/jbrowse-plugin-apollo/src/LinearApolloSixFrameDisplay/glyphs/GeneGlyph.ts index 75db4bcfc..cd6c05cbb 100644 --- a/packages/jbrowse-plugin-apollo/src/LinearApolloSixFrameDisplay/glyphs/GeneGlyph.ts +++ b/packages/jbrowse-plugin-apollo/src/LinearApolloSixFrameDisplay/glyphs/GeneGlyph.ts @@ -45,10 +45,11 @@ let forwardFillLight: CanvasPattern | null = null let backwardFillLight: CanvasPattern | null = null let forwardFillDark: CanvasPattern | null = null let backwardFillDark: CanvasPattern | null = null -const canvas = globalThis.document.createElement('canvas') -// @ts-expect-error getContext is undefined in the web worker -// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -if (canvas?.getContext) { +// globalThis.document is undefined in the web worker, where this module is +// also loaded (but never uses these patterns, which are main-thread-only +// rendering fills) +const canvas = globalThis.document?.createElement('canvas') +if (canvas) { for (const direction of ['forward', 'backward']) { for (const themeMode of ['light', 'dark']) { const canvas = document.createElement('canvas')