Skip to content

Commit 036cb99

Browse files
committed
fix: iridiscence
1 parent 25cbbb6 commit 036cb99

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apps/dashboard/components/bits/Iridiscence.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export default function Iridescence({
7171
const ctn = ctnDom.current;
7272
const renderer = new Renderer();
7373
const gl = renderer.gl;
74+
75+
// Check if WebGL context was created successfully
76+
if (!gl) {
77+
console.error('WebGL context not available');
78+
return;
79+
}
80+
7481
gl.clearColor(1, 1, 1, 1);
7582

7683
let program: Program | null = null;
@@ -122,7 +129,9 @@ export default function Iridescence({
122129
}
123130
}
124131
animateId = requestAnimationFrame(update);
125-
ctn.appendChild(gl.canvas);
132+
if (gl.canvas) {
133+
ctn.appendChild(gl.canvas);
134+
}
126135

127136
function handleMouseMove(e: MouseEvent) {
128137
const rect = ctn.getBoundingClientRect();
@@ -144,7 +153,9 @@ export default function Iridescence({
144153
if (mouseReact) {
145154
ctn.removeEventListener('mousemove', handleMouseMove);
146155
}
147-
ctn.removeChild(gl.canvas);
156+
if (gl.canvas && ctn.contains(gl.canvas)) {
157+
ctn.removeChild(gl.canvas);
158+
}
148159
gl.getExtension('WEBGL_lose_context')?.loseContext();
149160
};
150161
}, [color, speed, amplitude, mouseReact]);

0 commit comments

Comments
 (0)