@inertiajs/svelte 2.3.15 → 2.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "2.3.15",
3
+ "version": "2.3.17",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -19,7 +19,8 @@
19
19
  "files": [
20
20
  "dist",
21
21
  "!dist/**/*.test.*",
22
- "!dist/**/*.spec.*"
22
+ "!dist/**/*.spec.*",
23
+ "resources"
23
24
  ],
24
25
  "type": "module",
25
26
  "types": "./dist/index.d.ts",
@@ -36,14 +37,14 @@
36
37
  },
37
38
  "devDependencies": {
38
39
  "@sveltejs/adapter-auto": "^3.3.1",
39
- "@sveltejs/kit": "^2.50.2",
40
+ "@sveltejs/kit": "^2.53.2",
40
41
  "@sveltejs/package": "^2.5.7",
41
42
  "@sveltejs/vite-plugin-svelte": "^3.1.2",
42
43
  "axios": "^1.13.5",
43
- "es-check": "^9.5.4",
44
+ "es-check": "^9.6.1",
44
45
  "publint": "^0.3.17",
45
46
  "svelte": "^4.2.20",
46
- "svelte-check": "^4.3.6",
47
+ "svelte-check": "^4.4.4",
47
48
  "tslib": "^2.8.1",
48
49
  "typescript": "^5.9.3",
49
50
  "vite": "^5.4.21"
@@ -55,7 +56,7 @@
55
56
  "@types/lodash-es": "^4.17.12",
56
57
  "laravel-precognition": "^1.0.2",
57
58
  "lodash-es": "^4.17.23",
58
- "@inertiajs/core": "2.3.15"
59
+ "@inertiajs/core": "2.3.17"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
@@ -0,0 +1,3 @@
1
+ # Inertia + Svelte
2
+
3
+ - IMPORTANT: Activate `inertia-svelte-development` when working with Inertia Svelte client-side patterns.
@@ -0,0 +1,372 @@
1
+ ---
2
+ name: inertia-svelte-development
3
+ 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."
4
+ license: MIT
5
+ metadata:
6
+ author: laravel
7
+ ---
8
+ @php
9
+ /** @var \Laravel\Boost\Install\GuidelineAssist $assist */
10
+ @endphp
11
+ # Inertia Svelte Development
12
+
13
+ ## When to Apply
14
+
15
+ Activate this skill when:
16
+
17
+ - Creating or modifying Svelte page components for Inertia
18
+ - Working with forms in Svelte (using `<Form>` or `useForm`)
19
+ - Implementing client-side navigation with `<Link>` or `router`
20
+ - Using v2 features: deferred props, prefetching, WhenVisible, InfiniteScroll, once props, flash data, or polling
21
+ - Building Svelte-specific features with the Inertia protocol
22
+
23
+ ## Documentation
24
+
25
+ Use `search-docs` for detailed Inertia v2 Svelte patterns and documentation.
26
+
27
+ ## Basic Usage
28
+
29
+ ### Page Components Location
30
+
31
+ Svelte page components should be placed in the `{{ $assist->inertia()->pagesDirectory() }}` directory.
32
+
33
+ ### Page Component Structure
34
+
35
+ @boostsnippet("Basic Svelte Page Component", "svelte")
36
+ <script>
37
+ export let users
38
+ </script>
39
+
40
+ <div>
41
+ <h1>Users</h1>
42
+ <ul>
43
+ {#each users as user (user.id)}
44
+ <li>{user.name}</li>
45
+ {/each}
46
+ </ul>
47
+ </div>
48
+ @endboostsnippet
49
+
50
+ ## Client-Side Navigation
51
+
52
+ ### Basic Link Component
53
+
54
+ Use `<Link>` for client-side navigation instead of traditional `<a>` tags:
55
+
56
+ @boostsnippet("Inertia Svelte Navigation", "svelte")
57
+ <script>
58
+ import { Link } from '@inertiajs/svelte'
59
+ </script>
60
+
61
+ <Link href="/">Home</Link>
62
+ <Link href="/users">Users</Link>
63
+ <Link href={`/users/${user.id}`}>View User</Link>
64
+ @endboostsnippet
65
+
66
+ ### Link With Method
67
+
68
+ @boostsnippet("Link With POST Method", "svelte")
69
+ <script>
70
+ import { Link } from '@inertiajs/svelte'
71
+ </script>
72
+
73
+ <Link href="/logout" method="post">Logout</Link>
74
+ @endboostsnippet
75
+
76
+ ### Prefetching
77
+
78
+ Prefetch pages to improve perceived performance:
79
+
80
+ @boostsnippet("Prefetch on Hover", "svelte")
81
+ <script>
82
+ import { Link } from '@inertiajs/svelte'
83
+ </script>
84
+
85
+ <Link href="/users" prefetch>Users</Link>
86
+ @endboostsnippet
87
+
88
+ ### Programmatic Navigation
89
+
90
+ @boostsnippet("Router Visit", "svelte")
91
+ <script>
92
+ import { router } from '@inertiajs/svelte'
93
+
94
+ function handleClick() {
95
+ router.visit('/users')
96
+ }
97
+
98
+ // Or with options
99
+ function createUser() {
100
+ router.visit('/users', {
101
+ method: 'post',
102
+ data: { name: 'John' },
103
+ onSuccess: () => console.log('Success!'),
104
+ })
105
+ }
106
+ </script>
107
+ @endboostsnippet
108
+
109
+ ## Form Handling
110
+
111
+ @if($assist->inertia()->hasFormComponent())
112
+ ### Form Component (Recommended)
113
+
114
+ The recommended way to build forms is with the `<Form>` component:
115
+
116
+ @boostsnippet("Form Component Example", "svelte")
117
+ <script>
118
+ import { Form } from '@inertiajs/svelte'
119
+ </script>
120
+
121
+ <Form action="/users" method="post" let:errors let:processing let:wasSuccessful>
122
+ <input type="text" name="name" />
123
+ {#if errors.name}
124
+ <div>{errors.name}</div>
125
+ {/if}
126
+
127
+ <input type="email" name="email" />
128
+ {#if errors.email}
129
+ <div>{errors.email}</div>
130
+ {/if}
131
+
132
+ <button type="submit" disabled={processing}>
133
+ {processing ? 'Creating...' : 'Create User'}
134
+ </button>
135
+
136
+ {#if wasSuccessful}
137
+ <div>User created!</div>
138
+ {/if}
139
+ </Form>
140
+ @endboostsnippet
141
+
142
+ ### Form Component With All Props
143
+
144
+ @boostsnippet("Form Component Full Example", "svelte")
145
+ <script>
146
+ import { Form } from '@inertiajs/svelte'
147
+ </script>
148
+
149
+ <Form
150
+ action="/users"
151
+ method="post"
152
+ let:errors
153
+ let:hasErrors
154
+ let:processing
155
+ let:progress
156
+ let:wasSuccessful
157
+ let:recentlySuccessful
158
+ let:clearErrors
159
+ let:resetAndClearErrors
160
+ let:defaults
161
+ let:isDirty
162
+ let:reset
163
+ let:submit
164
+ >
165
+ <input type="text" name="name" value={defaults.name} />
166
+ {#if errors.name}
167
+ <div>{errors.name}</div>
168
+ {/if}
169
+
170
+ <button type="submit" disabled={processing}>
171
+ {processing ? 'Saving...' : 'Save'}
172
+ </button>
173
+
174
+ {#if progress}
175
+ <progress value={progress.percentage} max="100">
176
+ {progress.percentage}%
177
+ </progress>
178
+ {/if}
179
+
180
+ {#if wasSuccessful}
181
+ <div>Saved!</div>
182
+ {/if}
183
+ </Form>
184
+ @endboostsnippet
185
+
186
+ @if($assist->inertia()->hasFormComponentResets())
187
+ ### Form Component Reset Props
188
+
189
+ The `<Form>` component supports automatic resetting:
190
+
191
+ - `resetOnError` - Reset form data when the request fails
192
+ - `resetOnSuccess` - Reset form data when the request succeeds
193
+ - `setDefaultsOnSuccess` - Update default values on success
194
+
195
+ Use the `search-docs` tool with a query of `form component resetting` for detailed guidance.
196
+
197
+ @boostsnippet("Form With Reset Props", "svelte")
198
+ <script>
199
+ import { Form } from '@inertiajs/svelte'
200
+ </script>
201
+
202
+ <Form
203
+ action="/users"
204
+ method="post"
205
+ resetOnSuccess
206
+ setDefaultsOnSuccess
207
+ let:errors
208
+ let:processing
209
+ let:wasSuccessful
210
+ >
211
+ <input type="text" name="name" />
212
+ {#if errors.name}
213
+ <div>{errors.name}</div>
214
+ {/if}
215
+
216
+ <button type="submit" disabled={processing}>
217
+ Submit
218
+ </button>
219
+ </Form>
220
+ @endboostsnippet
221
+ @else
222
+ Note: This version of Inertia does not support `resetOnError`, `resetOnSuccess`, or `setDefaultsOnSuccess` on the `<Form>` component. Using these props will cause errors. Upgrade to Inertia v2.2.0+ to use these features.
223
+ @endif
224
+
225
+ 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.
226
+
227
+ @endif
228
+
229
+ ### `useForm` Hook
230
+
231
+ @if($assist->inertia()->hasFormComponent() === false)
232
+ For Inertia v2.0.x: Build forms using the `useForm` hook as the `<Form>` component is not available until v2.1.0+.
233
+ @else
234
+ For more programmatic control or to follow existing conventions, use the `useForm` hook:
235
+ @endif
236
+
237
+ @boostsnippet("useForm Example", "svelte")
238
+ <script>
239
+ import { useForm } from '@inertiajs/svelte'
240
+
241
+ const form = useForm({
242
+ name: '',
243
+ email: '',
244
+ password: '',
245
+ })
246
+
247
+ function submit() {
248
+ $form.post('/users', {
249
+ onSuccess: () => $form.reset('password'),
250
+ })
251
+ }
252
+ </script>
253
+
254
+ <form on:submit|preventDefault={submit}>
255
+ <input type="text" bind:value={$form.name} />
256
+ {#if $form.errors.name}
257
+ <div>{$form.errors.name}</div>
258
+ {/if}
259
+
260
+ <input type="email" bind:value={$form.email} />
261
+ {#if $form.errors.email}
262
+ <div>{$form.errors.email}</div>
263
+ {/if}
264
+
265
+ <input type="password" bind:value={$form.password} />
266
+ {#if $form.errors.password}
267
+ <div>{$form.errors.password}</div>
268
+ {/if}
269
+
270
+ <button type="submit" disabled={$form.processing}>
271
+ Create User
272
+ </button>
273
+ </form>
274
+ @endboostsnippet
275
+
276
+ ## Inertia v2 Features
277
+
278
+ ### Deferred Props
279
+
280
+ Use deferred props to load data after initial page render:
281
+
282
+ @boostsnippet("Deferred Props with Empty State", "svelte")
283
+ <script>
284
+ export let users
285
+ </script>
286
+
287
+ <div>
288
+ <h1>Users</h1>
289
+ {#if !users}
290
+ <div class="animate-pulse">
291
+ <div class="h-4 bg-gray-200 rounded w-3/4 mb-2"></div>
292
+ <div class="h-4 bg-gray-200 rounded w-1/2"></div>
293
+ </div>
294
+ {:else}
295
+ <ul>
296
+ {#each users as user (user.id)}
297
+ <li>{user.name}</li>
298
+ {/each}
299
+ </ul>
300
+ {/if}
301
+ </div>
302
+ @endboostsnippet
303
+
304
+ ### Polling
305
+
306
+ Automatically refresh data at intervals:
307
+
308
+ @boostsnippet("Polling Example", "svelte")
309
+ <script>
310
+ import { router } from '@inertiajs/svelte'
311
+ import { onMount, onDestroy } from 'svelte'
312
+
313
+ export let stats
314
+
315
+ let interval
316
+
317
+ onMount(() => {
318
+ interval = setInterval(() => {
319
+ router.reload({ only: ['stats'] })
320
+ }, 5000) // Poll every 5 seconds
321
+ })
322
+
323
+ onDestroy(() => {
324
+ clearInterval(interval)
325
+ })
326
+ </script>
327
+
328
+ <div>
329
+ <h1>Dashboard</h1>
330
+ <div>Active Users: {stats.activeUsers}</div>
331
+ </div>
332
+ @endboostsnippet
333
+
334
+ ### WhenVisible
335
+
336
+ Lazy-load a prop when an element scrolls into view. Useful for deferring expensive data that sits below the fold:
337
+
338
+ @boostsnippet("WhenVisible Example", "svelte")
339
+ <script>
340
+ import { WhenVisible } from '@inertiajs/svelte'
341
+
342
+ export let stats
343
+ </script>
344
+
345
+ <div>
346
+ <h1>Dashboard</h1>
347
+
348
+ <!-- stats prop is loaded only when this section scrolls into view -->
349
+ <WhenVisible data="stats" buffer={200}>
350
+ <div>
351
+ <p>Total Users: {stats.total_users}</p>
352
+ <p>Revenue: {stats.revenue}</p>
353
+ </div>
354
+
355
+ <svelte:fragment slot="fallback">
356
+ <div class="animate-pulse">Loading stats...</div>
357
+ </svelte:fragment>
358
+ </WhenVisible>
359
+ </div>
360
+ @endboostsnippet
361
+
362
+ ## Server-Side Patterns
363
+
364
+ Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines.
365
+
366
+ ## Common Pitfalls
367
+
368
+ - Using traditional `<a>` links instead of Inertia's `<Link>` component (breaks SPA behavior)
369
+ - Forgetting to add loading states (skeleton screens) when using deferred props
370
+ - Not handling the `undefined` state of deferred props before data loads
371
+ - Using `<form>` without preventing default submission (use `<Form>` component or `on:submit|preventDefault`)
372
+ - Forgetting to check if `<Form>` component is available in your Inertia version