Skip to content

Commit 55a241f

Browse files
committed
feat(website): minor improvements
1 parent 123f5c1 commit 55a241f

File tree

4 files changed

+80
-67
lines changed

4 files changed

+80
-67
lines changed

apps/website/components/EffectLayer.tsx

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ function createUniforms(width: number, height: number) {
195195
};
196196
}
197197

198+
function createRenderer(canvas: HTMLCanvasElement, width: number, height: number, dpr = 2) {
199+
return new Renderer({
200+
alpha: true,
201+
antialias: true,
202+
canvas,
203+
depth: false,
204+
dpr,
205+
height,
206+
powerPreference: "high-performance",
207+
premultipliedAlpha: true,
208+
webgl: 2,
209+
width,
210+
});
211+
}
212+
198213
export type EffectLayerProps = PropsWithChildren<{
199214
className?: string;
200215
}>;
@@ -203,6 +218,7 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
203218
const rRaf = useRef<number>(null);
204219
const rRoot = useRef<HTMLDivElement>(null);
205220
const rCanvas = useRef<HTMLCanvasElement>(null);
221+
const isActive = useRef<boolean>(false);
206222

207223
useEffect(() => {
208224
if (rRoot.current == null) return;
@@ -212,18 +228,7 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
212228
const canvas = rCanvas.current;
213229
const rect = root.getBoundingClientRect();
214230
const uniforms = createUniforms(rect.width, rect.height);
215-
const renderer = new Renderer({
216-
alpha: true,
217-
antialias: false,
218-
canvas,
219-
depth: false,
220-
dpr: window.devicePixelRatio,
221-
height: rect.height,
222-
powerPreference: "high-performance",
223-
premultipliedAlpha: true,
224-
webgl: 2,
225-
width: rect.width,
226-
});
231+
const renderer = createRenderer(canvas, rect.width, rect.height, window.devicePixelRatio);
227232

228233
const { gl } = renderer;
229234
const geometry = new Triangle(gl);
@@ -236,27 +241,34 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
236241
const mesh = new Mesh(gl, { geometry, program });
237242

238243
function update(time: number) {
244+
if (!isActive.current) return;
239245
uniforms.uTime.value = time * 0.001;
240246
renderer.render({ scene: mesh });
241247
rRaf.current = requestAnimationFrame(update);
242248
}
243249

250+
function resize(rect: DOMRect) {
251+
if (!isActive.current) return;
252+
uniforms.uResolution.value.set(rect.width, rect.height);
253+
renderer.setSize(rect.width, rect.height);
254+
renderer.render({ scene: mesh });
255+
}
256+
244257
const ro = new ResizeObserver((entries) => {
245-
for (const entry of entries) {
246-
if (entry.target !== root) continue;
247-
const rect = entry.contentRect;
248-
uniforms.uResolution.value.set(rect.width, rect.height);
249-
renderer.setSize(rect.width, rect.height);
250-
renderer.render({ scene: mesh });
251-
return;
252-
}
258+
if (!isActive.current) return;
259+
if (entries.length == null) return;
260+
requestAnimationFrame(() => {
261+
resize(root.getBoundingClientRect());
262+
});
253263
});
254264

255265
ro.observe(root);
256266
rRaf.current = requestAnimationFrame(update);
257267
canvas.style.opacity = "1";
268+
isActive.current = true;
258269

259270
return () => {
271+
isActive.current = false;
260272
canvas.style.opacity = "0";
261273
if (rRaf.current != null) cancelAnimationFrame(rRaf.current);
262274
ro.disconnect();
@@ -296,5 +308,6 @@ const styles = {
296308
"transition-opacity",
297309
"duration",
298310
"ease-[ease-in-out]",
311+
"pointer-events-none",
299312
),
300313
};

apps/website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"fumadocs-twoslash": "3.1.1",
2121
"fumadocs-typescript": "4.0.3",
2222
"fumadocs-ui": "15.2.12",
23-
"lucide-react": "^0.506.0",
23+
"lucide-react": "^0.507.0",
2424
"next": "^15.3.1",
2525
"next-view-transitions": "^0.3.4",
2626
"ogl": "^1.0.11",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"jiti": "^2.4.2",
7777
"lefthook": "^1.11.12",
7878
"markdownlint": "^0.37.4",
79-
"nx": "20.7.2",
79+
"nx": "20.8.1",
8080
"publint": "^0.3.12",
8181
"react": "^19.1.0",
8282
"react-dom": "^19.1.0",

pnpm-lock.yaml

Lines changed: 45 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)