Skip to content

Commit 0722e8a

Browse files
authored
Merge pull request #7 from inertiajs/form-precognition
Precognition docs
2 parents adc83a2 + 2e80598 commit 0722e8a

File tree

2 files changed

+769
-0
lines changed

2 files changed

+769
-0
lines changed

v2/core-concepts/the-protocol.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ The following headers are automatically sent by Inertia when making requests. Yo
147147
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.
148148
</ParamField>
149149

150+
The following headers are used for [Precognition](/v2/the-basics/forms#precognition) validation requests.
151+
152+
<ParamField header="Precognition" type="boolean">
153+
Set to `true` to indicate this is a Precognition validation request.
154+
</ParamField>
155+
156+
<ParamField header="Precognition-Validate-Only" type="string">
157+
Comma-separated list of field names to validate.
158+
</ParamField>
159+
150160
## Response Headers
151161

152162
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.
@@ -163,6 +173,20 @@ The following headers should be sent by your server-side adapter in Inertia resp
163173
Set to `X-Inertia` to help browsers correctly differentiate between HTML and JSON responses.
164174
</ParamField>
165175

176+
The following headers are used for [Precognition](/v2/the-basics/forms#precognition) validation responses.
177+
178+
<ParamField header="Precognition" type="string">
179+
Set to `true` to indicate this is a Precognition validation response.
180+
</ParamField>
181+
182+
<ParamField header="Precognition-Success" type="string">
183+
Set to `true` when validation passes with no errors, combined with a `204 No Content` status code.
184+
</ParamField>
185+
186+
<ParamField header="Vary" type="string">
187+
Set to `Precognition` on all responses when the Precognition middleware is applied.
188+
</ParamField>
189+
166190
## The Page Object
167191

168192
Inertia shares data between the server and client via a page object. This object includes the necessary information required to render the page component, update the browser's history state, and track the site's asset version. The page object can include the following properties:
@@ -522,3 +546,10 @@ Inertia uses specific HTTP status codes to handle different scenarios.
522546
| **302 Found** | Standard redirect response. Inertia's server-side adapters automatically convert this to `303 See Other` when returned after `PUT`, `PATCH`, or `DELETE` requests. |
523547
| **303 See Other** | Used for redirects after non-GET requests. This status code tells the browser to make a `GET` request to the redirect URL, preventing duplicate form submissions that could occur if the browser repeated the original request method. |
524548
| **409 Conflict** | Returned when there's an asset version mismatch or for external redirects. For asset mismatches, this prompts a full page reload. For external redirects, the response includes an `X-Inertia-Location` header and triggers a `window.location` redirect client-side. |
549+
550+
The following status codes are used for [Precognition](/v2/the-basics/forms#precognition) validation requests.
551+
552+
| Status Code | Description |
553+
|:------------------------------|:------------------------------------------------------------------------------------------------|
554+
| **204 No Content** | Successful Precognition validation request with no validation errors. |
555+
| **422 Unprocessable Entity** | Precognition validation request with validation errors. The response body contains the errors. |

0 commit comments

Comments
 (0)