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.
Inertia Svelte Development
When to Apply
Activate this skill when:
- Creating or modifying Svelte page components for Inertia
- Working with forms in Svelte (using
<Form>oruseForm) - Implementing client-side navigation with
<Link>orrouter - 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
Users
-
{#each users as user (user.id)}
- {user.name} {/each}
Client-Side Navigation
Basic Link Component
Use <Link> for client-side navigation instead of traditional <a> tags:
Link With Method
Prefetching
Prefetch pages to improve perceived performance:
Programmatic Navigation
Form Handling
Form Component (Recommended)
The recommended way to build forms is with the <Form> component:
Form Component Reset Props
The <Form> component supports automatic resetting:
resetOnError- Reset form data when the request failsresetOnSuccess- Reset form data when the request succeedssetDefaultsOnSuccess- Update default values on success
Use the search-docs tool with a query of form component resetting for detailed guidance.
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.
useForm Hook
For more programmatic control or to follow existing conventions, use the useForm hook:
Inertia v2 Features
Deferred Props
Use deferred props to load data after initial page render:
Users
{#if !users}-
{#each users as user (user.id)}
- {user.name} {/each}
Polling
Automatically refresh data at intervals:
Dashboard
Server-Side Patterns
Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines.
Common Pitfalls
- Using traditional
<a>links instead of Inertia's<Link>component (breaks SPA behavior) - Forgetting to add loading states (skeleton screens) when using deferred props
- Not handling the
undefinedstate of deferred props before data loads - Using
<form>without preventing default submission (use<Form>component oron:submit|preventDefault) - Forgetting to check if
<Form>component is available in your Inertia version