--- name: inertia-svelte-development description: >- Develops Inertia.js v2 Svelte client-side applications. Activates when creating Svelte pages, forms, or navigation; using Link, Form, or router; working with deferred props, prefetching, or polling; or when user mentions Svelte with Inertia, Svelte pages, Svelte forms, or Svelte navigation. --- @php /** @var \Laravel\Boost\Install\GuidelineAssist $assist */ @endphp # Inertia Svelte Development ## When to Apply Activate this skill when: - Creating or modifying Svelte page components for Inertia - Working with forms in Svelte (using `
` or `useForm`) - Implementing client-side navigation with `` or `router` - Using v2 features: deferred props, prefetching, or polling - Building Svelte-specific features with the Inertia protocol ## Documentation Use `search-docs` for detailed Inertia v2 Svelte patterns and documentation. ## Basic Usage ### Page Components Location Svelte page components should be placed in the `resources/js/Pages` directory. ### Page Component Structure @boostsnippet("Basic Svelte Page Component", "svelte")

Users

@endboostsnippet ## Client-Side Navigation ### Basic Link Component Use `` for client-side navigation instead of traditional `` tags: @boostsnippet("Inertia Svelte Navigation", "svelte") Home Users View User @endboostsnippet ### Link With Method @boostsnippet("Link With POST Method", "svelte") Logout @endboostsnippet ### Prefetching Prefetch pages to improve perceived performance: @boostsnippet("Prefetch on Hover", "svelte") Users @endboostsnippet ### Programmatic Navigation @boostsnippet("Router Visit", "svelte") @endboostsnippet ## Form Handling @if($assist->inertia()->hasFormComponent()) ### Form Component (Recommended) The recommended way to build forms is with the `` component: @boostsnippet("Form Component Example", "svelte") {#if errors.name}
{errors.name}
{/if} {#if errors.email}
{errors.email}
{/if} {#if wasSuccessful}
User created!
{/if} @endboostsnippet @if($assist->inertia()->hasFormComponentResets()) ### Form Component Reset Props The `
` component supports automatic resetting: - `resetOnError` - Reset form data when the request fails - `resetOnSuccess` - Reset form data when the request succeeds - `setDefaultsOnSuccess` - Update default values on success Use the `search-docs` tool with a query of `form component resetting` for detailed guidance. @boostsnippet("Form With Reset Props", "svelte") {#if errors.name}
{errors.name}
{/if}
@endboostsnippet @else Note: This version of Inertia does not support `resetOnError`, `resetOnSuccess`, or `setDefaultsOnSuccess` on the `
` component. Using these props will cause errors. Upgrade to Inertia v2.2.0+ to use these features. @endif Forms can also be built using the `useForm` hook for more programmatic control. Use the `search-docs` tool with a query of `useForm helper` for guidance. @endif ### `useForm` Hook @if($assist->inertia()->hasFormComponent() === false) For Inertia v2.0.x: Build forms using the `useForm` hook as the `` component is not available until v2.1.0+. @else For more programmatic control or to follow existing conventions, use the `useForm` hook: @endif @boostsnippet("useForm Example", "svelte") {#if $form.errors.name}
{$form.errors.name}
{/if} {#if $form.errors.email}
{$form.errors.email}
{/if} {#if $form.errors.password}
{$form.errors.password}
{/if}
@endboostsnippet ## Inertia v2 Features ### Deferred Props Use deferred props to load data after initial page render: @boostsnippet("Deferred Props with Empty State", "svelte")

Users

{#if !users}
{:else}
    {#each users as user (user.id)}
  • {user.name}
  • {/each}
{/if}
@endboostsnippet ### Polling Automatically refresh data at intervals: @boostsnippet("Polling Example", "svelte")

Dashboard

Active Users: {stats.activeUsers}
@endboostsnippet ## Server-Side Patterns Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines. ## Common Pitfalls - Using traditional `
` links instead of Inertia's `` component (breaks SPA behavior) - Forgetting to add loading states (skeleton screens) when using deferred props - Not handling the `undefined` state of deferred props before data loads - Using `
` without preventing default submission (use `` component or `on:submit|preventDefault`) - Forgetting to check if `` component is available in your Inertia version