--- 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." license: MIT metadata: author: laravel --- @php /** @var \Laravel\Boost\Install\GuidelineAssist $assist */ @endphp # Inertia Svelte development ## Documentation Use `search-docs` for detailed Inertia v2 Svelte patterns and documentation. ## Basic usage ### Page components location Place Svelte page components in the `{{ $assist->inertia()->pagesDirectory() }}` 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 `` 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 For details, run the `search-docs` tool with the query `form component resetting`. @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 causes errors. To use these props, upgrade to Inertia v2.2.0+. @endif For more programmatic control, you can also build forms with the `useForm` hook. For guidance, run the `search-docs` tool with the query `useForm helper`. @endif ### `useForm` hook @if($assist->inertia()->hasFormComponent() === false) In Inertia v2.0.x, build forms with the `useForm` hook. 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 the initial page render: @boostsnippet("Deferred Props with Empty State", "svelte")

Users

{#if !users}
{:else} {/if}
@endboostsnippet ### Polling Use the `usePoll` hook to refresh data automatically at intervals. The hook cleans up on unmount and throttles polling when the browser tab is inactive. @boostsnippet("Basic Polling", "svelte")

Dashboard

Active Users: {stats.activeUsers}
@endboostsnippet @boostsnippet("Polling With Request Options and Manual Control", "svelte")

Dashboard

Active Users: {stats.activeUsers}
@endboostsnippet - `autoStart` (default `true`): set to `false` to start polling manually with the returned `start()` function - `keepAlive` (default `false`): set to `true` to prevent throttling when the browser tab is inactive ## Server-side patterns The inertia-laravel guidelines cover server-side patterns such as Inertia::render, props, and middleware. ## 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 the `` component or `on:submit|preventDefault`) - Forgetting to check whether the `` component is available in your Inertia version