You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: v1/advanced/asset-versioning.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Inertia::version($version);
31
31
Inertia::version(fn () => $version); // Lazily...
32
32
```
33
33
34
-
## Cache busting
34
+
## Cache Busting
35
35
36
36
Asset refreshing in Inertia works on the assumption that a hard page visit will trigger your assets to reload. However, Inertia doesn't actually do anything to force this. Typically this is done with some form of cache busting. For example, appending a version query parameter to the end of your asset URLs.
Copy file name to clipboardExpand all lines: v1/advanced/csrf-protection.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: CSRF Protection
4
4
5
5
<Warning>This is documentation for Inertia.js v1, which is no longer actively maintained. Please refer to the [v2 docs](/v2) for the latest information.</Warning>
6
6
7
-
## Making requests
7
+
## Making Requests
8
8
9
9
Laravel automatically includes the proper CSRF token when making requests via Inertia or Axios. However, if you're using Laravel, be sure to omit the `csrf-token` meta tag from your project, as this will prevent the CSRF token from refreshing properly.
10
10
@@ -70,7 +70,7 @@ Axios automatically checks for the existence of an `XSRF-TOKEN` cookie. If it's
70
70
71
71
The easiest way to implement this is using server-side middleware. Simply include the `XSRF-TOKEN`cookie on each response, and then verify the token using the `X-XSRF-TOKEN` header sent in the requests from axios.
72
72
73
-
## Handling mismatches
73
+
## Handling Mismatches
74
74
75
75
When a CSRF token mismatch occurs, your server-side framework will likely throw an exception that results in an error response. For example, when using Laravel, a `TokenMismatchException` is thrown which results in a `419` error page. Since that isn't a valid Inertia response, the error is shown in a modal.
Some events, such as `before`, `invalid`, and `error`, support cancellation, allowing you to prevent Inertia's default behavior. Just like native events, the event will be cancelled if only one event listener calls `event.preventDefault()`.
In addition to the global events described throughout this page, Inertia also provides a number of [event callbacks](/manual-visits#event-callbacks) that fire when manually making Inertia visits.
Copy file name to clipboardExpand all lines: v1/advanced/partial-reloads.mdx
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ As an example, consider a "user index" page that includes a list of users, as we
10
10
11
11
Partial reloads only work for visits made to the same page component.
12
12
13
-
## Only certain props
13
+
## Only Certain Props
14
14
15
15
To perform a partial reload, use the `only` visit option to specify which data the server should return. This option should be an array of keys which correspond to the keys of the props.
16
16
@@ -50,7 +50,7 @@ router.visit(url, {
50
50
51
51
</CodeGroup>
52
52
53
-
## Except certain props
53
+
## Except Certain Props
54
54
55
55
In addition to the `only` visit option you can also use the `except` option to specify which data the server should exclude. This option should also be an array of keys which correspond to the keys of the props.
56
56
@@ -90,7 +90,7 @@ router.visit(url, {
90
90
91
91
</CodeGroup>
92
92
93
-
## Router shorthand
93
+
## Router Shorthand
94
94
95
95
Since partial reloads can only be made to the same page component the user is already on, it almost always makes sense to just use the `router.reload()` method, which automatically uses the current URL.
It's also possible to perform partial reloads with Inertia links using the `only` property.
128
128
@@ -156,7 +156,7 @@ import { inertia, Link } from '@inertiajs/svelte'
156
156
157
157
</CodeGroup>
158
158
159
-
## Lazy data evaluation
159
+
## Lazy Data Evaluation
160
160
161
161
For partial reloads to be most effective, be sure to also use lazy data evaluation when returning props from your server-side routes or controllers. This can be accomplished by wrapping all optional page data in a closure.
That's it! Now, as you navigate from one page to another, the progress bar will be added and removed from the page.
104
104
105
-
### Handling cancelled visits
105
+
### Handling Cancelled Visits
106
106
107
107
While this custom progress implementation works great for page visits that finish properly, it would be nice to handle cancelled visits as well. First, for interrupted visits (those that get cancelled as a result of a new visit), the progress bar should simply be reset back to the start position. Second, for manually cancelled visits, the progress bar should be immediately removed from the page.
108
108
@@ -121,7 +121,7 @@ NProgress.remove()
121
121
})
122
122
```
123
123
124
-
### File upload progress
124
+
### File Upload Progress
125
125
126
126
Let's take this a step further. When files are being uploaded, it would be great to update the loading indicator to reflect the upload progress. This can be done using the `progress` event.
Now, instead of the progress bar "trickling" while the files are being uploaded, it will actually update it's position based on the progress of the request. We limit the progress here to 90%, since we still need to wait for a response from the server.
137
137
138
-
### Loading indicator delay
138
+
### Loading Indicator Delay
139
139
140
140
The last thing we're going to implement is a loading indicator delay. It's often preferable to delay showing the loading indicator until a request has taken longer than 250-500 milliseconds. This prevents the loading indicator from appearing constantly on quick page visits, which can be visually distracting.
141
141
@@ -187,7 +187,7 @@ return
187
187
188
188
That's it, you now have a beautiful custom page loading indicator!
189
189
190
-
### Complete example
190
+
### Complete Example
191
191
192
192
For convenience, here is the full source code of the final version of our custom loading indicator.
Copy file name to clipboardExpand all lines: v1/advanced/remembering-state.mdx
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ For example, if a user partially completes a form, then navigates away, and then
10
10
11
11
To mitigate this issue, you can tell Inertia which local component state to save in the browser history.
12
12
13
-
## Saving local state
13
+
## Saving Local State
14
14
15
15
To save local component state to the history state, use the `remember` feature to tell Inertia which data it should remember.
16
16
@@ -79,7 +79,7 @@ let form = remember({
79
79
80
80
Now, whenever your local `form` state changes, Inertia will automatically save this data to the history state and will also restore it on history navigation.
81
81
82
-
## Multiple components
82
+
## Multiple Components
83
83
84
84
If your page contains multiple components that use the remember functionality provided by Inertia, you need to provide a unique key for each component so that Inertia knows which data to restore to each component.
85
85
@@ -190,7 +190,7 @@ let form = remember({
190
190
191
191
</CodeGroup>
192
192
193
-
## Form helper
193
+
## Form Helper
194
194
195
195
If you're using the [Inertia form helper](/forms#form-helper), you can pass a unique form key as the first argument when instantiating your form. This will cause the form data and errors to automatically be remembered.
196
196
@@ -226,7 +226,7 @@ const form = useForm(`EditUser:${user.id}\
226
226
227
227
</CodeGroup>
228
228
229
-
## Manually saving state
229
+
## Manually Saving State
230
230
231
231
The `remember` property in Vue 2, and the `useRemember` hook in Vue 3, React, and Svelte all watch for data changes and automatically save those changes to the history state. Then, Inertia will restore the data on page load.
Copy file name to clipboardExpand all lines: v1/advanced/scroll-management.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@ title: Scroll Management
4
4
5
5
<Warning>This is documentation for Inertia.js v1, which is no longer actively maintained. Please refer to the [v2 docs](/v2) for the latest information.</Warning>
6
6
7
-
## Scroll resetting
7
+
## Scroll Resetting
8
8
9
9
When navigating between pages, Inertia mimics default browser behavior by automatically resetting the scroll position of the document body (as well as any [scroll regions](#scroll-regions) you've defined) back to the top.
10
10
11
11
In addition, Inertia keeps track of the scroll position of each page and automatically restores that scroll position as you navigate forward and back in history.
12
12
13
-
## Scroll preservation
13
+
## Scroll Preservation
14
14
15
15
Sometimes it's desirable to prevent the default scroll resetting when making visits. You can disable this behavior by setting the `preserveScroll` option to `false`.
16
16
@@ -142,7 +142,7 @@ import { inertia, Link } from '@inertiajs/svelte'
142
142
143
143
</CodeGroup>
144
144
145
-
## Scroll regions
145
+
## Scroll Regions
146
146
147
147
If your app doesn't use document body scrolling, but instead has scrollable elements (using the `overflow` CSS property), scroll resetting will not work.
Copy file name to clipboardExpand all lines: v1/advanced/server-side-rendering.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Server-side rendering pre-renders your JavaScript pages on the server, allowing
12
12
13
13
Server-side rendering uses Node.js to render your pages in a background process; therefore, Node must be available on your server for server-side rendering to function properly.
14
14
15
-
## Laravel starter kits
15
+
## Laravel Starter Kits
16
16
17
17
If you are using [Laravel Breeze or Jetstream](https://laravel.com/docs/starter-kits), you may install the starter kit's scaffolding with Inertia SSR support pre-configured using the `--ssr` flag.
If you are not using a Laravel starter kit and would like to manually configure SSR, we'll first install the additional dependencies required for server-side rendering. This is only necessary for the Vue adapters, so you can skip this step if you're using React or Svelte.
27
27
@@ -51,7 +51,7 @@ Then, make sure you have the latest version of the Inertia Laravel adapter insta
51
51
composer require inertiajs/inertia-laravel
52
52
```
53
53
54
-
## Add server entry-point
54
+
## Add Server Entry-Point
55
55
56
56
Next, we'll create a `resources/js/ssr.js` file within our Laravel project that will serve as our SSR entry point.
57
57
@@ -164,7 +164,7 @@ refresh: true,
164
164
})
165
165
```
166
166
167
-
## Update npm script
167
+
## Update Npm Script
168
168
169
169
Next, let's update the `build` script in our `package.json` file to also build our new `ssr.js` file.
170
170
@@ -182,7 +182,7 @@ Now you can build both your client-side and server-side bundles.
182
182
npm run build
183
183
```
184
184
185
-
## Running the SSR server
185
+
## Running the SSR Server
186
186
187
187
Now that you have built both your client-side and server-side bundles, you should be able run the Node-based Inertia SSR server using the following command.
188
188
@@ -192,7 +192,7 @@ php artisan inertia:start-ssr
192
192
193
193
With the server running, you should be able to access your app within the browser with server-side rendering enabled. In fact, you should be able to disable JavaScript entirely and still navigate around your application.
194
194
195
-
## Client side hydration
195
+
## Client Side Hydration
196
196
197
197
Since your website is now being server-side rendered, you can instruct <VueSpecific>Vue</VueSpecific><ReactSpecific>React</ReactSpecific><SvelteSpecific>Svelte</SvelteSpecific> to "hydrate" the static markup and make it interactive instead of re-rendering all the HTML that we just generated.
Copy file name to clipboardExpand all lines: v1/advanced/testing.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,15 @@ title: Testing
6
6
7
7
There are many different ways to test an Inertia application. This page provides a quick overview of the tools available.
8
8
9
-
## End-to-end tests
9
+
## End-to-end Tests
10
10
11
11
One popular approach to testing your JavaScript page components is to use an end-to-end testing tool like [Cypress](https://www.cypress.io/) or [Laravel Dusk](https://laravel.com/docs/dusk). These are browser automation tools that allow you to run real simulations of your app in the browser. These tests are known to be slower; however, since they test your application at the same layer as your end users, they can provide a lot of confidence that your app is working correctly. And, since these tests are run in the browser, your JavaScript code is actually executed and tested as well.
12
12
13
-
## Client-side unit tests
13
+
## Client-side Unit Tests
14
14
15
15
Another approach to testing your page components is using a client-side unit testing framework, such as [Jest](https://jestjs.io/) or [Mocha](https://mochajs.org/). This approach allows you to test your JavaScript page components in isolation using Node.js.
16
16
17
-
## Endpoint tests
17
+
## Endpoint Tests
18
18
19
19
In addition to testing your JavaScript page components, you will likely want to also test the Inertia responses that are returned by your server-side framework. A popular approach to doing this is using endpoint tests, where you make requests to your application and examine the responses. Laravel [provides tooling](https://laravel.com/docs/http-tests) for executing these types of tests.
0 commit comments