Skip to content

Protocol handling

The adapter implements the server side of the Inertia.js v3 protocol. This page lists what it does for you, which helps when debugging requests in the browser dev tools.

Responses

RequestResponse
Regular GET (first visit)200, root view with <script data-page="app" type="application/json">
Inertia visit (X-Inertia: true)200, JSON page object, headers X-Inertia: true and Vary: X-Inertia

Every response carries Vary: X-Inertia, so caches never mix HTML and JSON for the same URL.

Page object

PropertyWhen
component, props, url, versionalways (props.errors always present)
sharedPropsshared props exist and exposeSharedPropKeys is enabled
deferredPropsdeferred props on a full visit
mergeProps, prependProps, deepMergeProps, matchPropsOnmerge props are sent
oncePropsonce props exist
scrollPropsscroll props are sent
rescuedPropsa deferred prop with rescue failed
flashflash data exists
encryptHistory, clearHistory, preserveFragmentwhen true

Request headers

HeaderHandling
X-InertiaIdentifies Inertia visits
X-Inertia-VersionCompared with the current version on GET requests
X-Inertia-Partial-ComponentPartial reload filters apply only when it matches the rendered component
X-Inertia-Partial-Data / X-Inertia-Partial-Exceptonly / except prop paths
X-Inertia-ResetProps whose merge metadata is reset
X-Inertia-Error-BagNests default-bag validation errors under the bag name
X-Inertia-Except-Once-PropsOnce props the client already holds
X-Inertia-Infinite-Scroll-Merge-Intentappend or prepend for scroll props
X-XSRF-TOKENCopied to Yii's CSRF header before validation
Purpose: prefetchFragment redirects are not converted

Lifecycle

When the component is bootstrapped, it hooks into every request:

StageBehaviour
BootstrapRegisters JsonParser for application/json bodies
Before requestAccepts the CSRF token from X-XSRF-TOKEN
Before actionOutdated asset version on an Inertia GET: 409 with X-Inertia-Location and X-Inertia-Version, the action does not run
Before sendAdds Vary: X-Inertia
Before send (Inertia requests)Restores Location for Yii AJAX redirects (X-Redirect); redirects back when the response is empty; 302303 after PUT/PATCH/DELETE; redirects with a #fragment409 with X-Inertia-Redirect
Before sendSends the XSRF-TOKEN cookie for Inertia requests and rendered pages

Encoding

Page objects are encoded with JSON_HEX_TAG (so user data cannot close the <script> element) and JSON_UNESCAPED_UNICODE. Invalid UTF-8 throws a JsonException. Empty objects are encoded as {}, not [].

Released under the MIT License.