Index of every page on this site: llms.txt
All skills
spences10 avatar

/sveltekit-structure

@5fe4989
Run it yourself

SvelteKit structure guidance. Use for routing, layouts, error handling, SSR, or svelte:boundary. Covers file naming, nested layouts, error boundaries, pending UI, and hydration.

Use this Skill: https://skilld.dev/gh/spences10/svelte-skills-kit/sveltekit-structure

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencessvelte-boundary.md

≈883 tokens on demand. Your agent reads this file only when SKILL.md points to it.

svelte:boundary Component

Available in Svelte 5.3+

Two Purposes

  1. Error boundaries - catch rendering errors
  2. Pending UI - show loading state while await resolves

Basic Error Boundary

<svelte:boundary onerror={(e, reset) => console.error(e)}>
	<RiskyComponent />

	{#snippet failed(error, reset)}
		<p>Error: {error.message}</p>
		<button onclick={reset}>Try again</button>
	{/snippet}
</svelte:boundary>

Pending UI (Loading States)

⚠️ Known Bug: <svelte:boundary> + {@const await} causes infinite navigation loops during client-side page transitions when pages share async queries. See sveltejs/svelte#17717. Use {#await} blocks until this is fixed.

With experimental.async: true (Svelte 5.36+), {@const await} is possible but not safe for pages with shared queries or navigation:

<!-- ⚠️ Causes navigation loops - use {#await} instead -->
<svelte:boundary>
	{#snippet pending()}
		<LoadingSpinner />
	{/snippet}

	{@const data = await loadData()}
	<DataView {data} />
</svelte:boundary>

Safe alternative:

{#await loadData()}
	<LoadingSpinner />
{:then data}
	<DataView {data} />
{:catch error}
	<p>Error: {error.message}</p>
{/await}

Combined Error + Pending

Use svelte:boundary for error catching only, with {#await} for async data:

<svelte:boundary onerror={logError}>
	{#snippet failed(error, reset)}
		<p>Failed to load user</p>
		<button onclick={reset}>Retry</button>
	{/snippet}

	{#await fetchUser()}
		<p>Loading user...</p>
	{:then user}
		<UserProfile {user} />
	{:catch error}
		<p>Error: {error.message}</p>
	{/await}
</svelte:boundary>

What Gets Caught

Caught:

  • Errors during rendering
  • Errors in $effect

NOT Caught:

  • Event handler errors (onclick, etc.)
  • Errors after setTimeout
  • Async errors outside boundary's await

vs +error.svelte

Feature svelte:boundary +error.svelte
Scope Component subtree Route segment
Reset Built-in reset function Navigate away
Pending Yes (pending snippet) No
Use case Component-level Page-level

Error Tracking Integration

<svelte:boundary
	onerror={(error, reset) => {
		// Send to Sentry, LogRocket, etc.
		errorTracker.captureException(error);
	}}
>
	<App />

	{#snippet failed(error, reset)}
		<ErrorFallback {error} {reset} />
	{/snippet}
</svelte:boundary>

Nested Boundaries

Inner boundary catches first:

<svelte:boundary>
	<!-- Outer fallback -->
	{#snippet failed(e)}
		<p>Outer caught: {e.message}</p>
	{/snippet}

	<svelte:boundary>
		<!-- Inner fallback -->
		{#snippet failed(e)}
			<p>Inner caught: {e.message}</p>
		{/snippet}

		<ComponentThatMightFail />
	</svelte:boundary>
</svelte:boundary>

Key Points

  • Use svelte:boundary for component-level error isolation
  • Use +error.svelte for route-level error pages
  • pending snippet shows only on initial load (not on refresh - no flicker)
  • failed snippet replaces content on error
  • reset function lets users retry
  • Errors in event handlers are NOT caught
  • Requires experimental.async: true in svelte.config.js for {@const await}
  • ⚠️ Bug: {@const await} + navigation causes infinite loops (#17717) — use {#await} instead

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides documentation and structural guidance for SvelteKit projects. It includes a workflow command instruction for validating the skill files, but contains no malicious patterns, prompt injections, or unauthorized resource access.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    7/7 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 5fe4989. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago

README badge

README badge for spences10/svelte-skills-kit/sveltekit-structure