- How you use it
- cli_tool
- What it can do
- installs software · network
- What's inside
The option
| Option | Acli_tool · v1.1.1Svelte sv CLI |
|---|---|
| How you use it | cli_tool |
| What it can do | installs software · network |
| What's inside |
What this thread does
Migrate ordinary shared state one dependency chain at a time into rune-aware factories, while keeping stores that provide useful subscription or stream semantics.
Do first: check package.json for the installed Svelte major
1. Record installed dependencies and passing checks before refactoring. This recipe starts with store-based code on Svelte 5, not a whole Svelte 4 upgrade. As of November 2026, the latest stable reference is Svelte 5.59.1, checked 2026-11-24. 2. Classify each store: component-local value, shared UI model, request/user state, or external stream/custom subscription. Keep stores where their explicit subscription lifecycle remains useful; the stores guide still supports them and recommends runes for ordinary extracted/shared state. 3. Move one model to a .svelte.ts factory. Return an object whose property can be read and mutated; avoid exporting a reassigned primitive. Example authored replacement for a counter store:
// counter.svelte.ts
export function createCounter(initial = 0) {
const state = $state({ count: initial });
return {
state,
increment() { state.count += 1; }
};
}
<script lang="ts">
import { createCounter } from './counter.svelte';
const counter = createCounter();
let doubled = $derived(counter.state.count * 2);
</script>
<button onclick={() => counter.increment()}>
{counter.state.count} / {doubled}
</button>
Read counter.state.count at the use site. Destructuring the primitive count into another variable takes a value rather than creating a reactive link. The $state documentation explains proxy state and cross-module restrictions; $derived tracks reactive computations. 4. If siblings must share the model, create it in their common owner and pass it down, or put it in context. For SvelteKit SSR, create user/request state per request/component tree. Do not replace a module-global store holding user data with module-global rune state: both can leak data between requests. Follow SvelteKit state management. 5. Update consumers and derived values together. Keep $store access for stores inside components. At a non-component boundary that needs rune access to a retained store, use the documented fromStore(store).current; use toStore when a store consumer must observe rune state. See svelte/store interoperability. 6. Verify initial render, mutation, two consumers sharing one instance, destruction/subscription cleanup, and server rendering with two separate user contexts. Run the project's existing type, component and build checks before moving to the next model.
What changes, and what does not
| Existing operation | Migration action |
|---|---|
writable used as a shared mutable UI model | Consider an object created by $state inside a .svelte.ts factory. Replace .set/.update calls at each consumer deliberately. |
derived value dependent on migrated state | Use $derived in a rune-aware scope, or expose a getter for a computation. Do not leave a store dependency graph silently disconnected. |
| Side-effecting subscription | Preserve its cleanup; choose an effect only if its lifecycle and client-only execution fit. |
| External observable/custom store with useful lifecycle | Keep its store contract, bridging only the boundary that needs it. |
$effect runs in the browser, not during SSR. Prefer $derived for values the page needs on first server render. An effect that writes a second state variable to mirror the first adds avoidable synchronization.
Broader migration boundary
The Svelte 5 migration guide allows legacy and rune components together. If you also convert component syntax, review props/bindings, event handlers, snippets, component construction and lifecycle differences separately. Its npx sv migrate svelte-5 automates some syntax changes, not every semantic decision. A store refactor is not evidence that all major-version breaking changes have been handled.
Options, cost and limits — checked 2026-10-28
| Option | Wins when | Loses when | Pick this if |
|---|---|---|---|
| Retain stores | Subscription APIs, explicit cleanup or existing integrations are useful | Simple shared state requires repetitive wrapper code | Existing behaviour is correct and the subscription contract earns its place. |
| Rune factory | You want ordinary reactive state and reusable logic owned by a component tree | Consumers still require store APIs and the ownership boundary is unclear | You can migrate one complete dependency chain and keep request state isolated. |
Both APIs are part of Svelte; this is no new hosted subscription or service-quota decision. The real cost is refactoring, testing consumers and maintaining interoperability, not a promised runtime speedup.
Public evidence
newsve, Svelte discussion 14835, 2024-12-26: “migrate bottom-up and not top-down”. The author reports rune/store dependency surprises and recommends changing dependent layers together. This is useful historical migration experience, not an authoritative statement that every example in the discussion remains current; use the current interoperability docs above.
Recommendation by constraint
Solo developer: keep working stores and migrate one model only when it simplifies code. Small team: consider rune factories for new ordinary state when ownership is clear and consumers do not require store APIs, retaining store boundaries until their consumers are ready. Enterprise SvelteKit app: prioritize SSR ownership and regression checks; migrate by model/component boundary rather than forcing a global rewrite.
Prompt for the agent
Inventory stores and their consumers in this Svelte 5 app. Pick one ordinary UI model, preserve subscription boundaries and convert its complete dependency chain to a per-owner rune factory. Show where SSR instances are created and test separate user contexts. Keep unrelated component and framework upgrades separate.
Mistakes and Limits
Do not destructure reactive primitives expecting live references, mechanically replace every derived import, or use module-global user state. No app was compiled, benchmarked or migrated here. The community evidence is one older discussion. This does not establish a previous supported Svelte 4 baseline or audit all intervening release notes; apps still on Svelte 4 need the complete official upgrade review first.
Started from a post by @Svelte contributors, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.