Skip to content

Commit 8e2b9a2

Browse files
committed
Update the-protocol.mdx
1 parent 7d0366e commit 8e2b9a2

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

v2/core-concepts/the-protocol.mdx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ The following headers are automatically sent by Inertia when making requests. Yo
143143
Indicates whether the requested data should be appended or prepended when using [Infinite scroll](/v2/data-props/infinite-scroll).
144144
</ParamField>
145145

146+
<ParamField header="X-Inertia-Page-Once-Props" type="string">
147+
Comma-separated list of non-expired [once prop](/v2/data-props/once-props) keys already loaded on the client. The server will skip resolving these props unless explicitly requested via a partial reload or force refreshed server-side.
148+
</ParamField>
149+
146150
## Response Headers
147151

148152
The following headers should be sent by your server-side adapter in Inertia responses. If you're using an official server-side adapter, these are handled automatically.
@@ -211,6 +215,10 @@ Inertia shares data between the server and client via a page object. This object
211215
Configuration for client-side [lazy loading of props](/v2/data-props/deferred-props).
212216
</ParamField>
213217

218+
<ParamField body="onceProps" type="object">
219+
Configuration for [once props](/v2/data-props/once-props) that should only be resolved once and reused on subsequent pages. Each entry maps a key to an object containing the `prop` name and optional `expiresAt` timestamp (in milliseconds).
220+
</ParamField>
221+
214222
On standard full page visits, the page object is JSON encoded into the `data-page` attribute in the root `<div>`. On Inertia visits (as indicated by the presence of the `X-Inertia` header), the page object is returned as the JSON payload.
215223

216224
### Basic Page Object
@@ -360,6 +368,78 @@ When using [Infinite scroll](/v2/data-props/infinite-scroll), the page object in
360368
}
361369
```
362370

371+
### Page Object with Once Props
372+
373+
When using [once props](/v2/data-props/once-props), the page object includes an `onceProps` configuration. Each entry maps a key to the prop name and an optional expiration timestamp.
374+
375+
```json
376+
{
377+
"component": "Billing/Plans",
378+
"props": {
379+
"errors": {},
380+
"plans": [
381+
{
382+
"id": 1,
383+
"name": "Basic"
384+
},
385+
{
386+
"id": 2,
387+
"name": "Pro"
388+
}
389+
]
390+
},
391+
"url": "/billing/plans",
392+
"version": "6b16b94d7c51cbe5b1fa42aac98241d5",
393+
"clearHistory": false,
394+
"encryptHistory": false,
395+
"onceProps": {
396+
"plans": {
397+
"prop": "plans",
398+
"expiresAt": null
399+
}
400+
}
401+
}
402+
```
403+
404+
When navigating to a subsequent page that includes the same once prop, the client sends the loaded keys in the `X-Inertia-Page-Once-Props` header. The server skips resolving these props and excludes them from the response. The client reuses the previously loaded values.
405+
406+
```http
407+
REQUEST
408+
GET: https://example.com/billing/upgrade
409+
Accept: text/html, application/xhtml+xml
410+
X-Requested-With: XMLHttpRequest
411+
X-Inertia: true
412+
X-Inertia-Version: 6b16b94d7c51cbe5b1fa42aac98241d5
413+
X-Inertia-Page-Once-Props: plans
414+
415+
RESPONSE
416+
HTTP/1.1 200 OK
417+
Content-Type: application/json
418+
419+
{
420+
"component": "Billing/Upgrade",
421+
"props": {
422+
"errors": {},
423+
"currentPlan": {
424+
"id": 1,
425+
"name": "Basic"
426+
}
427+
},
428+
"url": "/billing/upgrade",
429+
"version": "6b16b94d7c51cbe5b1fa42aac98241d5",
430+
"clearHistory": false,
431+
"encryptHistory": false,
432+
"onceProps": {
433+
"plans": {
434+
"prop": "plans",
435+
"expiresAt": null
436+
}
437+
}
438+
}
439+
```
440+
441+
Note that `plans` is included in `onceProps` but not in `props` since it was already loaded on the client. The `onceProps` key identifies the once prop across pages, while `prop` specifies the actual prop name. These may differ when using [custom keys](/v2/data-props/once-props#custom-keys).
442+
363443
## Asset Versioning
364444

365445
One common challenge with single-page apps is refreshing site assets when they've been changed. Inertia makes this easy by optionally tracking the current version of the site's assets. In the event that an asset changes, Inertia will automatically make a full-page visit instead of an XHR visit.

0 commit comments

Comments
 (0)