fix(frontend): gracefully handle missing WebGL context (#1147)

Wrap the OGL Renderer instantiation in a try-catch so the app does not
crash when WebGL is unavailable (e.g. hardware acceleration disabled).
The Galaxy background simply does not render instead of taking down the
entire page.

Fixes #1144

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
Matt Van Horn
2026-03-16 06:22:17 -07:00
committed by GitHub
parent 3212c7c5a2
commit 609ff5849f

View File

@@ -198,11 +198,28 @@ export default function Galaxy({
useEffect(() => {
if (!ctnDom.current) return;
const ctn = ctnDom.current;
const renderer = new Renderer({
alpha: transparent,
premultipliedAlpha: false,
});
let renderer;
try {
renderer = new Renderer({
alpha: transparent,
premultipliedAlpha: false,
});
} catch (error) {
console.warn(
"Galaxy: WebGL is not available. The galaxy background will not be rendered.",
error,
);
return;
}
const gl = renderer.gl;
if (!gl) {
console.warn(
"Galaxy: WebGL context is null. The galaxy background will not be rendered.",
);
return;
}
if (transparent) {
gl.enable(gl.BLEND);