Skip to content

Commit 24e2e03

Browse files
author
Les Moffat
committed
RD-578 Dynamically create canvas ctx to avoid breaking on isomorphic apps
1 parent 871153f commit 24e2e03

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/utils/webgl-utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,14 @@ export function degreesToRadians(degrees: number) {
190190
}
191191

192192
// to avoid recreating the ctx each time
193-
const colorConvertCtx = document.createElement("canvas").getContext("2d");
193+
let ctx: CanvasRenderingContext2D | null;
194194

195195
function colorToRgbOrHex(color: string): string {
196-
// because cavnas 2D context automagically converts
196+
// because canvas 2D context automagically converts
197197
// any valid css color to a hex string
198198
// or an RGBA string
199-
const ctx = colorConvertCtx;
199+
ctx = ctx ?? document.createElement("canvas").getContext("2d");
200+
200201
if (!ctx) {
201202
return "#000000";
202203
}

0 commit comments

Comments
 (0)