Skip to content

Commit

Permalink
Handle disabled webgl
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Oct 15, 2024
1 parent 279df6a commit 6287016
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apps/website/src/components/donut.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"use client";

import { useWebGL } from "@/hooks/use-webgl";
import Spline from "@splinetool/react-spline/next";

export async function Donut() {
const { webglDisabled } = useWebGL();

if (webglDisabled) {
return null;
}

return (
<div className="animate-webgl-scale-in-fade">
<Spline
Expand Down
21 changes: 21 additions & 0 deletions apps/website/src/hooks/use-webgl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect, useState } from "react";

function isWebGLDisabled(): boolean {
const canvas = document.createElement("canvas");
const gl =
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
return !gl;
}

export function useWebGL() {
const [webglDisabled, setWebGLDisabled] = useState(false);

useEffect(() => {
if (typeof window !== "undefined") {
const disabled = isWebGLDisabled();
setWebGLDisabled(disabled);
}
}, []);

return { webglDisabled };
}
1 change: 0 additions & 1 deletion apps/website/src/lib/fetch-github-stars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export async function fetchGithubStars() {
next: {
revalidate: 3600,
},
cache: "force-cache",
},
);

Expand Down

0 comments on commit 6287016

Please sign in to comment.