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: docs/guide/client-side-setup.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,3 +292,26 @@ createInertiaApp({
292
292
// ...
293
293
})
294
294
```
295
+
296
+
> [!NOTE]
297
+
> Make sure the [`root_dom_id`](/guide/configuration#root_dom_id) configuration option matches the `id` property in your client-side setup.
298
+
299
+
## Script Element for Page Data
300
+
301
+
By default, Inertia stores the initial page data in a `data-page` attribute on the root element. You may configure Inertia to use a `<script type="application/json">` element instead, which is slightly faster and easier to inspect in your browser's dev tools.
302
+
303
+
```js
304
+
createInertiaApp({
305
+
// ...
306
+
defaults: {
307
+
future: {
308
+
useScriptElementForInitialPage:true,
309
+
},
310
+
},
311
+
})
312
+
```
313
+
314
+
You should also set the [`use_script_element_for_initial_page`](/guide/configuration#use_script_element_for_initial_page) config option to `true`.
315
+
316
+
> [!NOTE]
317
+
> Be sure to also update your [SSR entry point](/guide/server-side-rendering#add-server-entry-point) if you're using server-side rendering.
Copy file name to clipboardExpand all lines: docs/guide/configuration.md
+56Lines changed: 56 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,3 +151,59 @@ The default value will be changed to `true` in the next major version.
151
151
Specifies the base controller class for the internal `StaticController` used to render [Shorthand routes](/guide/routing#shorthand-routes).
152
152
153
153
By default, Inertia Rails creates a `StaticController` that inherits from `ApplicationController`. You can use this option to specify a different base controller (for example, to include custom authentication, layout, or before actions).
154
+
155
+
### `root_dom_id`
156
+
157
+
**Default**: `'app'`
158
+
**ENV**: `INERTIA_ROOT_DOM_ID`
159
+
160
+
@available_since rails=master
161
+
162
+
Specifies the DOM element ID used for the root Inertia.js element.
163
+
164
+
```ruby
165
+
InertiaRails.configure do |config|
166
+
config.root_dom_id ='inertia-app'
167
+
end
168
+
```
169
+
170
+
> [!NOTE]
171
+
> Make sure your client-side Inertia setup uses the same ID when calling `createInertiaApp`.
When enabled the initial page data is rendered in a `<script type="application/json">` element instead of the `data-page` attribute on the root `<div>`.
181
+
This provides two main benefits:
182
+
183
+
1.**Smaller page size**: JSON data doesn't require HTML entity encoding, reducing the overall HTML payload size.
184
+
2.**Faster parsing**: The browser can parse raw JSON directly from the script element, which is more efficient than parsing HTML-encoded JSON from an attribute.
185
+
186
+
```ruby
187
+
InertiaRails.configure do |config|
188
+
config.use_script_element_for_initial_page =true
189
+
end
190
+
```
191
+
192
+
When disabled (default), the HTML output looks like:
Copy file name to clipboardExpand all lines: docs/guide/deferred-props.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,8 @@ export default () => (
121
121
122
122
:::
123
123
124
+
## Multiple Deferred Props
125
+
124
126
If you need to wait for multiple deferred props to become available, you can specify an array to the `data` prop.
125
127
126
128
:::tabs key:frameworks
@@ -189,3 +191,21 @@ export default () => (
189
191
```
190
192
191
193
:::
194
+
195
+
## Combining with Once Props
196
+
197
+
@available_since rails=master core=2.2.20
198
+
199
+
You may pass the `once: true` argument to a deferred prop to ensure the data is resolved only once and remembered by the client across subsequent navigations.
0 commit comments