From 7c77f50f7ab77edd3c1b92235c717a0ee1b1e499 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 20 Apr 2026 07:25:21 +0000 Subject: [PATCH] Docs: modernize Svelte integration guide for Svelte 5 runes - Switch to Svelte 5 runes: $state for reactive values, onclick for event handlers. - Fix SSR snippet: onMount's async callback cannot return a cleanup function synchronously, so the engine was never destroyed. Move teardown to a separate onDestroy. - Use $state around hf in the SSR snippet so disabled={!hf} updates when the engine finishes mounting. - Add TypeScript (lang="ts") for parity with the React and Vue guides, with a note for JS users. - Clarify that the SSR warning is about duplicated work per render, not an unconditional crash. --- docs/guide/integration-with-svelte.md | 54 +++++++++++++++++---------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/docs/guide/integration-with-svelte.md b/docs/guide/integration-with-svelte.md index ac6e39f53..3251034d4 100644 --- a/docs/guide/integration-with-svelte.md +++ b/docs/guide/integration-with-svelte.md @@ -4,18 +4,20 @@ The HyperFormula API is identical in a Svelte app and in plain JavaScript. What Install with `npm install hyperformula`. For other options, see the [client-side installation](client-side-installation.md) section. +The snippets below target **Svelte 5** (runes mode) — the current stable release. They assume a project created from the official `sv` / SvelteKit templates, which enable runes by default. + ::: warning SvelteKit SSR -The primary snippet below assumes a browser environment. If you use SvelteKit with default SSR, skip to [Server-side rendering](#server-side-rendering-sveltekit) — `HyperFormula.buildFromArray` at ` - - + + {#if result !== null}

Result: {result}

{/if} @@ -52,7 +53,7 @@ Declare the engine at the top of ` - - + + {#if result !== null}

Result: {result}

{/if} ``` +Two details that matter for correctness: + +- **`$state` around `hf`** — the engine is assigned asynchronously inside `onMount`, so the variable needs to be reactive for `disabled={!hf}` to flip once the engine is ready. Svelte 5 does not deep-proxy class instances stored in `$state`, so the HyperFormula instance remains untouched; only the reassignment is tracked. +- **Dynamic `await import('hyperformula')` + type-only `import type`** — the runtime import keeps the module out of the server bundle, while `import type` is erased at compile time, so it adds nothing to the server payload while still giving you full type checking. ## Next steps