Skip to content

Update Svelte integration guide for Svelte 5 and runes#1659

Draft
sequba wants to merge 17 commits intodevelopfrom
claude/review-svelte-integration-guide-6gybV
Draft

Update Svelte integration guide for Svelte 5 and runes#1659
sequba wants to merge 17 commits intodevelopfrom
claude/review-svelte-integration-guide-6gybV

Conversation

@sequba
Copy link
Copy Markdown
Contributor

@sequba sequba commented Apr 20, 2026

Context

The Svelte integration guide was written for Svelte 4 and needs to be updated to reflect Svelte 5's new runes-based reactivity system. The changes modernize the code examples and clarify best practices for using HyperFormula with current Svelte versions.

Changes

  • Target Svelte 5 (runes mode): Updated all code examples to use the $state rune for reactive variables instead of plain let declarations
  • Event handler syntax: Changed from on:click to onclick to match Svelte 5 conventions
  • Type annotations: Added TypeScript support with proper imports (import type) and inline type annotations using $state<Type>()
  • SSR guidance: Clarified the SvelteKit SSR section with better explanation of why onMount is necessary and corrected the async cleanup pattern (separate onDestroy instead of returning cleanup from async onMount)
  • Reactivity explanations: Added detailed notes about when to use $state (for values that drive UI updates) vs. plain const (for references that never change, like the HyperFormula instance)
  • Best practices: Documented that table cell expressions don't need reactivity since they read static data, and explained how to handle mutations if needed

How did you test your changes?

Documentation review — verified that all code examples follow Svelte 5 patterns and are syntactically correct. The changes are purely documentation updates with no runtime code modifications.

Types of changes

  • Change to the documentation

Checklist:

  • I have reviewed the guidelines about Contributing to HyperFormula and I confirm that my code follows the code style of this project.
  • My changes require a documentation update.

https://claude.ai/code/session_0123ZjQT79obK9A6DXCwaKUW

marcin-kordas-hoc and others added 17 commits April 9, 2026 17:51
Add idiomatic code examples to React, Angular, Vue, and Svelte
integration pages showing HyperFormula initialization and reading
calculated values. Each guide uses framework-specific patterns
(React hooks, Angular service, Vue ref/markRaw, Svelte reactivity).

Closes HF-122.
Per feedback, snippets now focus on framework-specific integration
patterns (useRef/useEffect, @Injectable, markRaw/ref, Svelte reactivity)
with placeholder comments for data and configuration rather than
concrete values. The Demo section link is reworded from "Explore the
full working example" to "For a more advanced example" to signal that
the Stackblitz demo is a richer, separate project.

Part of HF-122.
Expand React, Angular, Vue and Svelte integration guides to cover
framework-specific concerns that the previous skeleton snippets omitted:

- Convert all snippets to TypeScript with HyperFormula/CellValue imports
- Add licenseKey: 'gpl-v3' to every buildFromArray call
- Inline `npm install hyperformula` install command
- React: runnable JSX with controlled inputs, try/catch around setCellContents,
  React.StrictMode note, Next.js App Router SSR section with 'use client' and
  dynamic import
- Angular: modern standalone component + inject() + DestroyRef + Signals +
  OnPush, RxJS BehaviorSubject variant with AsyncPipe import note, NgZone
  runOutsideAngular section, provider-scope + DestroyRef rationale
- Vue: <script setup lang="ts">, expanded markRaw Proxy explanation and
  shallowRef trap, Nuxt SSR snippet, Pinia store with updateCell action,
  valuesUpdated event hook, inline v-for template
- Svelte: fixes memory leak by adding onDestroy(() => hf.destroy()), Svelte 5
  runes primary example plus Svelte 4 delta, SvelteKit SSR warning banner and
  dedicated onMount section with dynamic import, wired #each template with
  updateCell handler
Point readers from each integration guide to related topics they are
likely to need next: configuration options, basic operations (CRUD),
advanced usage (multi-sheet, named expressions), and custom functions.

Identical section in all four guides so the navigation experience is
consistent when switching between frameworks.
The Stackblitz demo links used \${...} JavaScript template literal syntax,
which is not interpolated by VuePress. VuePress 1 processes markdown as
Vue templates, so the correct syntax for accessing the injected
\$page.buildDateURIEncoded variable is Vue's {{ ... }} interpolation.

config.js line 79 documents the intended syntax explicitly:
  // inject current HF buildDate URI encoded as {{ \$page.buildDateURIEncoded }} variable

Before this fix, the cache-buster query string rendered as a literal
?v=\${\$page.buildDateURIEncoded} in the URL, breaking the cache-busting
behaviour on every Stackblitz demo link.

Note: the same issue exists in docs/guide/custom-functions.md:361 from
an earlier change; that is left for a separate fix.
…ntent)

tsc smoke check found that updateCell(value: unknown) does not satisfy
setCellContents which expects RawCellContent. Replace unknown with the
correct type and add missing RawCellContent imports in Angular, Vue and
Svelte guides.
Add framework-agnostic instruction file for AI coding assistants
(Claude Code, GitHub Copilot, Cursor, Gemini CLI). Covers the core
3-operation API surface, framework integration patterns with critical
rules (markRaw, onDestroy, StrictMode, DestroyRef, SSR guards),
key types, common mistakes to prevent, and project structure pointers.
Angular: switch primary pattern to BehaviorSubject/Observable (module-based),
matching the angular-demo on Stackblitz. Signal-based variant moved to a
'Signals variant (Angular 17+)' note. Cleanup section expanded with both
ngOnDestroy and DestroyRef options.

Svelte: switch primary pattern to Svelte 4 style (on:click, plain let),
matching the svelte-demo on Stackblitz. Svelte 5 runes variant moved to
a '### Svelte 5 (runes)' subsection. SSR section updated to use Svelte 4
as primary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
React: fix Next.js SSR pattern — 'use client' belongs in the component
file, not on page.tsx; server page uses dynamic(..., { ssr: false })

Angular: add CommonModule/standalone imports for *ngFor + async pipe;
add @for template for signals variant; add inject() context note

Vue: replace shallowRef with ref in Nuxt SSR snippet (shallowRef vs
markRaw contradiction); add hf.off() teardown to valuesUpdated example;
remove hf from Pinia store return value (devtools serialisation risk)

Svelte: fix CellValue type for result variable; fix SSR snippet to use
onMount return for cleanup instead of separate onDestroy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Vue: rewrite primary snippet to use class wrapper pattern matching
the vue-3-demo on Stackblitz. markRaw moved to Notes as alternative.

Angular: remove unnecessary `as CellValue[][]` casts (getSheetValues
already returns this type).

React: remove try/catch from handleCellEdit for consistency — no demo
uses error handling around setCellContents.

custom-functions.md: fix VuePress template syntax (${}→{{}}) so the
Stackblitz link renders the build date correctly.

AGENTS.md: update framework table to match actual guide primary
patterns (Angular=BehaviorSubject, Vue=class wrapper, Svelte=Svelte 4).
…polation

{{ $page.buildDateURIEncoded }} inside markdown link syntax [text](url{{ }})
breaks markdown-it parsing — links render as plain text instead of clickable
links. Switch to <a :href="..."> with Vue v-bind which VuePress handles
correctly since page data is available in template scope.
Per Kuba's review feedback: snippets must match what's in the Stackblitz
demos so we can guarantee they work correctly. Removed all patterns that
have never been tested with HyperFormula:

Angular: removed Signals variant (signal, inject, DestroyRef, OnPush,
@for), NgZone.runOutsideAngular section.

Svelte: removed Svelte 5 runes ($state) section.

Vue: removed markRaw alternative, Nuxt SSR with dynamic import,
valuesUpdated event listener, Pinia store sections.

These patterns can be re-added once validated by a framework consultant
or included in updated demos.
All four Stackblitz demos use the same interaction model: "Run calculations"
and "Reset" buttons with read-only table output. Aligned guides to match:

React: replaced editable <input onChange> with button-driven calculate/reset.
The onChange-per-keystroke pattern was not from the demo and caused issues
with partial formula input.

Angular: replaced standalone component with NgModule pattern (matching demo).
Replaced updateCell with calculate/reset methods matching EmployeesService.
Added buttons to template.

Vue: replaced dead handleUpdate/updateCell with getCalculatedValues/
getRawFormulas matching EmployeesDataProvider. Added Run/Reset buttons.
AGENTS.md: Vue SSR guard updated from "onMounted + dynamic import"
to "<ClientOnly> (Nuxt)" matching the actual guide content.

Svelte: renamed "Calculate" to "Run calculations" and added "Reset"
button for consistency with React/Angular/Vue guides. Reset is pure
UI (result = null), no HF API involved.
- 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.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 20, 2026

Performance comparison of head (7c77f50) vs base (d6a316c)

                                     testName |   base |   head | change
------------------------------------------------------------------------
                                      Sheet A | 487.59 | 487.07 | -0.11%
                                      Sheet B | 157.14 | 155.78 | -0.87%
                                      Sheet T | 139.25 | 140.09 | +0.60%
                                Column ranges |  471.1 | 473.29 | +0.46%
Sheet A:  change value, add/remove row/column |  15.54 |  15.18 | -2.32%
 Sheet B: change value, add/remove row/column | 132.81 | 131.66 | -0.87%
                   Column ranges - add column | 142.34 | 146.85 | +3.17%
                Column ranges - without batch |  433.5 | 443.18 | +2.23%
                        Column ranges - batch | 112.13 | 111.68 | -0.40%

@marcin-kordas-hoc
Copy link
Copy Markdown
Collaborator

Cherry-picked the async-onMount-cleanup correction into #1653 commit 8c8625031 — that's a real Svelte bug (cleanup function returned from an async callback is silently ignored), independent of Svelte 5 vs 4.

The Svelte 5 runes-refactor ($state, onclick, import type) was not picked up — same rationale as #1657/#1658: it breaks parity with the Stackblitz Svelte demo (Svelte 4 mode), which is the snippet-vs-demo foundation per 2026-04-10. Belongs in the Svelte specialist v2 pass.

Closing-suggestion: park (the only useful piece is already merged). I'll let you close at your discretion.

Base automatically changed from feature/hf-122-framework-integration-guides to develop May 7, 2026 12:17
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.18%. Comparing base (1852159) to head (7c77f50).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1659      +/-   ##
===========================================
+ Coverage    96.77%   97.18%   +0.41%     
===========================================
  Files          174      174              
  Lines        15086    15086              
  Branches      3223     3223              
===========================================
+ Hits         14599    14662      +63     
+ Misses         487      424      -63     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants