Skip to content

Commit 2e6b1ee

Browse files
Support Inertia v3 protocol metadata (#199)
* feat(inertia-sails): support Inertia v3 protocol metadata * feat(inertia): complete v3 template migration * test(ascent-vue): restore template smoke checks * feat(inertia-sails): support v3 fragments and rescue metadata * chore(inertia-sails): add js typecheck gate * chore(templates): refresh inertia-sails lockfiles
1 parent 3e3ad46 commit 2e6b1ee

108 files changed

Lines changed: 3056 additions & 1096 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Inertia Sails
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v3
12+
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: 18
17+
18+
- name: Install dependencies
19+
run: npm ci
20+
21+
- name: Run inertia-sails checks
22+
run: npm --workspace inertia-sails test

package-lock.json

Lines changed: 7 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"@commitlint/config-conventional": "^17.6.6",
2626
"husky": "^8.0.3",
2727
"lint-staged": "^13.2.2",
28-
"prettier": "2.8.8"
28+
"prettier": "2.8.8",
29+
"typescript": "^5.7.3"
2930
},
3031
"workspaces": [
3132
"packages/*"

packages/inertia-sails/README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ module.exports.inertia = {
3838
<%- shipwright.styles() %>
3939
</head>
4040
<body>
41-
<div id="app" data-page="<%- JSON.stringify(page) %>"></div>
41+
<div id="app"></div>
42+
<script type="application/json" data-page="app">
43+
<%- JSON.stringify(page).replace(/</g, '\\u003c') %>
44+
</script>
4245
<%- shipwright.scripts() %>
4346
</body>
4447
</html>
@@ -87,6 +90,19 @@ Return a URL string to redirect:
8790
return '/dashboard'
8891
```
8992

93+
#### Preserving URL fragments
94+
95+
When a standard Inertia redirect should carry the current hash to the next
96+
page, mark the redirect before returning the URL:
97+
98+
```js
99+
sails.inertia.preserveFragment()
100+
return '/articles/new-slug'
101+
```
102+
103+
If the user started from `/articles/old-slug#comments`, the Inertia client can
104+
carry `#comments` to the redirected page.
105+
90106
### Sharing Data
91107

92108
#### `share(key, value)`
@@ -191,6 +207,25 @@ return {
191207
}
192208
```
193209

210+
Deferred props can also be rescued when a non-critical callback fails:
211+
212+
```js
213+
return {
214+
page: 'dashboard',
215+
props: {
216+
analytics: sails.inertia
217+
.defer(async () => {
218+
return await Analytics.getExpensiveReport()
219+
})
220+
.rescue()
221+
}
222+
}
223+
```
224+
225+
When a rescued deferred prop throws, it is omitted from `props` and its key is
226+
reported in `rescuedProps`, allowing the client `<Deferred>` component to show
227+
its rescue slot instead of failing the whole deferred response.
228+
194229
### Merge Props
195230

196231
Merge with existing client-side data (useful for infinite scroll):
@@ -199,13 +234,29 @@ Merge with existing client-side data (useful for infinite scroll):
199234
// Shallow merge
200235
messages: sails.inertia.merge(() => newMessages)
201236

237+
// Prepend new items instead of appending
238+
notifications: sails.inertia.merge(() => newNotifications).prepend()
239+
240+
// Merge a nested array inside a paginated object
241+
users: sails.inertia.merge(() => paginatedUsers).append('data')
242+
243+
// Match existing items by ID when merging
244+
users: sails.inertia
245+
.merge(() => paginatedUsers)
246+
.append('data', {
247+
matchOn: 'id'
248+
})
249+
202250
// Deep merge (nested objects)
203251
settings: sails.inertia.deepMerge(() => updatedSettings)
252+
253+
// Deep merge with item matching
254+
chat: sails.inertia.deepMerge(() => chatState).matchOn('messages.id')
204255
```
205256

206257
### Infinite Scroll
207258

208-
Paginate data with automatic merge behavior. Works with Inertia.js v2's `<InfiniteScroll>` component:
259+
Paginate data with automatic merge behavior. Works with Inertia's `<InfiniteScroll>` component:
209260

210261
```js
211262
// Controller
@@ -244,6 +295,8 @@ defineProps({ invoices: Object })
244295
</template>
245296
```
246297

298+
`scroll()` targets the wrapped array for merging, such as `invoices.data`, and follows Inertia's infinite-scroll merge intent header so previous-page requests prepend while next-page requests append.
299+
247300
### History Encryption
248301

249302
Encrypt sensitive data in browser history:

0 commit comments

Comments
 (0)