1. Keep Canvas logic inside onMount
SvelteKit runs component scripts during SSR where window and HTMLCanvasElement do not exist. Initialize your 2D context and requestAnimationFrame loop inside onMount and cancel the frame on cleanup:
<script lang="ts">
import { onMount } from 'svelte';
let container: HTMLDivElement;
let canvas: HTMLCanvasElement;
// Paste rawPoints from Particle Logo (or JSON export)
const rawPoints: [number, number, string?][] = [];
onMount(() => {
const ctx = canvas.getContext('2d');
if (!ctx) return;
let raf = 0;
const render = () => {
// Draw particle frame on canvas
raf = requestAnimationFrame(render);
};
raf = requestAnimationFrame(render);
return () => cancelAnimationFrame(raf);
});
</script>
<div bind:this={container} class="particle-wrap">
<canvas bind:this={canvas}></canvas>
</div>
2. Two clean ways to ship
- Fastest (Free plan): Export the standalone HTML5 file from the workbench, save it to
static/logo.html, and render it via an<iframe src="/logo.html">. - Native component (Pro): Export the sampled JSON points alongside the 2D Canvas update loop from the HTML export so particle colors and backgrounds inherit your SvelteKit CSS variables directly.