Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Svelte Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-svelte-knowledge-patch)
---
name: svelte-knowledge-patch
description: Svelte
version: null
license: MIT
metadata:
author: Nevaberry
---
# Svelte knowledge patch
Load this skill when migrating Svelte components or SvelteKit applications,
working with runes and async rendering, implementing remote forms or queries,
or configuring routing, builds, and deployment.
Use the topic references for complete guidance, examples, and version qualifications.
> [!CAUTION]
> SvelteKit prerelease guidance may change before stable release.
> The affected guidance carries an item-level prerelease label.
## Reference index
| Reference | Topics |
| --- | --- |
| [Svelte 5 migration](references/svelte-5-migration.md) | Upgrade dependencies, component conversion, slots, retained reactive assignments |
| [Runes and components](references/runes-and-components.md) | State, async rendering, boundaries, context, snippets, inputs, reactivity, CSS, accessibility, debugging |
| [Remote forms](references/remote-forms.md) | Nested values, schemas, validation, submission state, resets, uploads, redirects, error pages |
| [Remote queries and commands](references/remote-queries-and-commands.md) | Optional inputs, template awaits, refreshes, live reconnects, response caching, failures |
| [SvelteKit routing and runtime](references/kit-routing-and-runtime.md) | Paths, parameters, navigation, rendering errors, hydration, observability, endpoints, security |
| [Tooling, build, and deployment](references/tooling-build-and-deployment.md) | SvelteKit migration, imports, environment variables, service workers, prerendering, adapters, Vite, types, compiler output |
## Upgrade and replacement checks
### Component migration
For projects on Svelte 3, complete the Svelte 4 migration before upgrading to Svelte 5.
The Svelte 5 upgrade pairs `svelte@^5` with `@sveltejs/vite-plugin-svelte@^4.0.0`.
With a component open in VS Code and the Svelte extension installed, run
**Migrate Component to Svelte 5 Syntax** from the Command Palette.
Svelte 5.57.2 rejects `let:` directives on a component invocation that also supplies
a `children` snippet. When migrating a default slot, pass its values as snippet
arguments and declare them as snippet parameters.
The Svelte 5.57.2 migrator preserves a dependency-free `$:` assignment when it cannot
convert it to a declaration; check the retained assignment when finishing migration.
### SvelteKit migration requirements
> **Prerelease (`3`):** This guidance may change before stable release.
SvelteKit 3 requires Svelte 5 and Vite 8. The migrator applies supported changes
and generates a TODO list for the rest:
```sh
npx sv@next migrate sveltekit-3 --tasks all --confirm
```
### SvelteKit configuration location
> **Prerelease (`3`):** This guidance may change before stable release.
Move SvelteKit configuration from `svelte.config.js` into `vite.config.ts`.
### Shared-code imports
> **Prerelease (`3`):** This guidance may change before stable release.
Replace `$lib` imports with Node subpath imports under `#lib`.
Spell out the filename and extension, including `index.ts` for a directory entry point.
### Generated application TypeScript config
> **Prerelease (`3`):** This guidance may change before stable release.
Set `extends` to `$app/tsconfig` in the app's `tsconfig.json`.
The generated base supplies more recommended compiler options; the app config
should specify `include` and `exclude` explicitly, with the service worker excluded.
### Environment imports and ambient types
SvelteKit 2.70.0 moves `defineEnvVars` to `@sveltejs/kit/env`.
Update the import in the environment variable configuration.
Svelte lists `@types/trusted-types` as a development dependency. If the application
relies on ambient types such as `TrustedHTML` from that package, declare it as a
direct development dependency.
### Async initialization constraints
During server rendering, `setContext()` after an `await` throws
`set_context_after_init`. Set context before the component's first `await`.
Starting in Svelte 5.58.1, experimental async mode requires `getAbortSignal()`
before the first `await` in the active effect or derived calculation.
Capture the signal before suspending and pass it to the asynchronous work.
## State and async rendering
Apply custom `Proxy` handlers to the result of `$state(...)` so intercepted
operations can still reach Svelte's reactive proxy.
`Object.hasOwn(proxy, key)` tracks whether a `$state` proxy owns the property;
adding or deleting it updates a derived check.
In Svelte 5.59.2, a write that throws `state_unsafe_mutation` leaves the reactive
class or `$state` proxy unchanged.
Use `$state.eager(value)` for immediate feedback after a user action when an
`await` expression would otherwise delay the UI update. It retains its eager
behavior in a variable initializer.
In Svelte 5.58.1, a fork's speculative values stay out of `$inspect` and
`$state.eager` until the fork commits.
`$effect.pending()` counts pending promises from component `await` expressions
in the current `<svelte:boundary>`; each nested boundary has its own count.
Svelte supports experimental asynchronous server rendering for components that
await data during rendering. In an async-enabled component, `await` in a
`{@const}` initializer gives the resolved value a name in the template.
## Boundaries, context, and snippets
A `<svelte:boundary>` can catch errors from its contents during server rendering
and render its `failed` snippet as a fallback.
Svelte 5.57.2 ignores stale boundary `reset` callbacks; use the callback supplied
for the current failure to retry rendering.
In Svelte 5.59.2, a surrounding boundary catches errors thrown while rendering
a deferred branch of an `{#await}` block.
Registered `onDestroy` callbacks run even when server rendering throws.
`createContext<T>()` returns a third function that checks whether context is
available. Call it during component initialization before reading optional context.
During initialization, `getContext(key)` can read a value the component previously
set with `setContext(key, value)`; lookup includes the current component and its ancestors.
An HTML element creates a lexical scope for its snippet declarations.
A snippet declared inside an element is visible to its siblings and their
descendants within that element. Svelte reports duplicate snippet or declaration
tag names in the same scope at compile time. Give each definition a unique name.
## Remote forms
In SvelteKit 2.53.2, `form.fields.set(...)` accepts incomplete nested objects,
and `form.fields.value()` is typed to reflect that nested fields can be missing.
Nested values set this way appear in the server-rendered form before hydration.
An unchecked checkbox is omitted from submission. Make its remote form schema
field optional, and supply a default if the handler needs a boolean.
Remote form data also omits file inputs with no selected file.
If an upload is optional, let the schema accept a missing field.
Use `submitted` for conditional submission feedback.
Resetting a remote form clears validation issues and touched state.
SvelteKit waits a tick before resetting a submitted form; code observing the
automatic reset can still see the submitted values until that tick.
`fields.branch.issues()` returns `undefined` when only `fields.branch.leaf` has
issues. Read the leaf field's `issues()` to display those messages.
Preflight validation remains active when `.preflight(schema)` precedes `.for(id)`.
## Remote queries and commands
Remote `query`, `command`, and `prerender` accept schemas with optional input in
SvelteKit 2.53.2. The handler can use a default when validated input is `undefined`.
A remote function call in a template no longer delays server rendering unless
the template awaits it. Use `await` when rendering needs the result.
A remote query can refresh another remote query while it runs.
As of SvelteKit 2.65.1, navigation with `invalidateAll: true` resets remote queries
before navigating.
Existing `for await...of` loops stay subscribed across `query.live` reconnects.
A reconnected stream that finishes without yielding preserves the last value;
the reconnect promise also settles on offline or interrupted attempts, allowing
`invalidateAll()` to finish.
SvelteKit 2.65.2 sends `Cache-Control: private, no-store` on remote responses,
preserves HTTP status and error bodies on transport failures, and avoids an
unhandled promise rejection when a failure is consumed through `current` and `error`.
## Routing and navigation
`resolve()` from `$app/paths` accepts a pathname with a search string, a hash, or both.
A route matcher's TypeScript type predicate narrows its page or layout parameter
in `$app/types`; the narrower type carries through to `$app/state` and hooks.
Navigation blurs the active element before updating the component, so `blur` and
`focusout` handlers still see the outgoing component's data.
Snapshots are restored after `afterNavigate` callbacks run; a callback reading
snapshot-backed state can still see the state from before restoration.
### Shallow navigation
> **Prerelease (`3`):** This guidance may change before stable release.
Use `goto` with `shallow: true` in place of `pushState` and `replaceState`.
Shallow navigation runs navigation hooks such as `beforeNavigate`, and
`persistState: true` keeps page state across a reload.
## Build and prerender checks
SvelteKit skips the client build when every route has `csr` disabled.
With `bundleStrategy: 'inline'`, SvelteKit 2.65.1 stops emitting the unused
standalone bundle and stylesheet files; account for their absence in deployment steps.
Prerendering fails in SvelteKit 2.65.2 if root `src/routes/+server.js` returns a
non-HTML response. Serve prerendered JSON or other non-HTML responses from a non-root route.
Prerendering gives pages precedence over endpoints; marking a route containing
both `+page` and `+server` as prerenderable fails early.
Use `kit.prerender.handleInvalidUrl` in `svelte.config.js` to control how the
prerender crawler handles invalid URLs it discovers.
In SvelteKit 2.65.2, use `building` to defer validation of explicit environment
variables supplied only at runtime.
## Diagnostics and tooling
In development, the default `$inspect(value)` logger includes a stack trace on
updates; stack traces are unavailable in the Svelte playground.
Put `$inspect.trace()` first in a function body to log the reactive state that
caused it to run again as part of an effect or derived value. This works in
development, including in helper functions called by the reaction.
Initialize server observability in `instrumentation.server.ts`.
SvelteKit can emit OpenTelemetry traces for the app.
SvelteKit and Svelte's language tools support TypeScript 6.