From fbdbbac7e178258a0b6d2d21f1fdb1c7867f878f Mon Sep 17 00:00:00 2001 From: Svyatoslav Kryukov Date: Sat, 15 Nov 2025 00:23:04 +0300 Subject: [PATCH 1/5] Add docs on defaults configuration --- docs/guide/client-side-setup.md | 94 +++++++++++++++++++++++++++++++++ docs/guide/error-handling.md | 17 ++++++ docs/guide/forms.md | 2 + docs/guide/manual-visits.md | 69 ++++++++++++++++++++++++ docs/guide/prefetching.md | 4 +- docs/guide/title-and-meta.md | 17 ++++++ 6 files changed, 201 insertions(+), 2 deletions(-) diff --git a/docs/guide/client-side-setup.md b/docs/guide/client-side-setup.md index 9029720d..ab3f5790 100644 --- a/docs/guide/client-side-setup.md +++ b/docs/guide/client-side-setup.md @@ -114,6 +114,100 @@ createInertiaApp({ The `setup` callback receives everything necessary to initialize the client-side framework, including the root Inertia `App` component. +## Configuring defaults + +You may pass a `defaults` object to `createInertiaApp()` to configure default settings for various features. You don't have to pass all keys, just the ones you want to tweak. + +```js +createInertiaApp({ + // ... + defaults: { + form: { + recentlySuccessfulDuration: 5000, + }, + prefetch: { + cacheFor: '1m', + hoverDelay: 150, + }, + visitOptions: (href, options) => { + return { + headers: { + ...options.headers, + 'X-Custom-Header': 'value', + }, + } + }, + }, +}) +``` + +The `visitOptions` callback receives the target URL and the current visit options, and should return an object with any options you want to override. For more details on the available configuration options, see the [forms](/guide/forms#form-errors), [prefetching](/guide/prefetching), and [manual visits](/guide/manual-visits#global-visit-options) documentation. + +### Updating at runtime + +You may also update configuration values at runtime using the exported `config` instance. This is +particularly useful when you need to adjust settings based on user preferences or application state. + +:::tabs key:frameworks +== Vue + +```js +import { router } from '@inertiajs/vue3' + +// Set a single value using dot notation... +config.set('form.recentlySuccessfulDuration', 1000) +config.set('prefetch.cacheFor', '5m') + +// Set multiple values at once... +config.set({ + 'form.recentlySuccessfulDuration': 1000, + 'prefetch.cacheFor': '5m', +}) + +// Get a configuration value... +const duration = config.get('form.recentlySuccessfulDuration') +``` + +== React + +```js +import { router } from '@inertiajs/react' + +// Set a single value using dot notation... +config.set('form.recentlySuccessfulDuration', 1000) +config.set('prefetch.cacheFor', '5m') + +// Set multiple values at once... +config.set({ + 'form.recentlySuccessfulDuration': 1000, + 'prefetch.cacheFor': '5m', +}) + +// Get a configuration value... +const duration = config.get('form.recentlySuccessfulDuration') +``` + +== Svelte 4|Svelte 5 + +```js +import { router } from '@inertiajs/svelte' + +// Set a single value using dot notation... +config.set('form.recentlySuccessfulDuration', 1000) +config.set('prefetch.cacheFor', '5m') + +// Set multiple values at once... +config.set({ + 'form.recentlySuccessfulDuration': 1000, + 'prefetch.cacheFor': '5m', +}) + +// Get a configuration value... +const duration = config.get('form.recentlySuccessfulDuration') +``` + +::: + # Resolving components The `resolve` callback tells Inertia how to load a page component. It receives a page name (string), and returns a page component module. How you implement this callback depends on which bundler (Vite or Webpack) you're using. diff --git a/docs/guide/error-handling.md b/docs/guide/error-handling.md index c808c214..a6facea1 100644 --- a/docs/guide/error-handling.md +++ b/docs/guide/error-handling.md @@ -6,6 +6,23 @@ One of the advantages to working with a robust server-side framework is the buil Inertia solves this issue by showing all non-Inertia responses in a modal. This means you get the same beautiful error-reporting you're accustomed to, even though you've made that request over XHR. +## Dialog element + +By default, Inertia displays error modals using a custom `
` overlay. However, you can opt-in to using the native HTML `` element instead, which provides built-in modal functionality including backdrop handling. + +To enable this, configure the `future.useDialogForErrorModal` option in your [application defaults](/guide/client-side-setup#configuring-defaults). + +```js +createInertiaApp({ + // resolve, setup, etc. + defaults: { + future: { + useDialogForErrorModal: true, + }, + }, +}) +``` + ## Production In production you will want to return a proper Inertia error response instead of relying on the modal-driven error reporting that is present during development. To accomplish this, you'll need to update your framework's default exception handler to return a custom error page. diff --git a/docs/guide/forms.md b/docs/guide/forms.md index 3378abc5..5301a0fa 100644 --- a/docs/guide/forms.md +++ b/docs/guide/forms.md @@ -1452,6 +1452,8 @@ $form.setError({ When a form has been successfully submitted, the `wasSuccessful` property will be `true`. In addition to this, forms have a `recentlySuccessful` property, which will be set to `true` for two seconds after a successful form submission. This property can be utilized to show temporary success messages. +You may customize the duration of the `recentlySuccessful` state by setting the `form.recentlySuccessfulDuration` option in your [application defaults](/guide/client-side-setup#configuring-defaults). The default value is `2000` milliseconds. + ### Resetting the Form To reset the form's values back to their default values, you can use the `reset()` method. diff --git a/docs/guide/manual-visits.md b/docs/guide/manual-visits.md index af9d8ee0..55b708f3 100644 --- a/docs/guide/manual-visits.md +++ b/docs/guide/manual-visits.md @@ -326,6 +326,75 @@ router.post('/users', data, { > [!NOTE] > The headers Inertia uses internally to communicate its state to the server take priority and therefore cannot be overwritten. +## Global visit options + +You may configure a `visitOptions` callback when [initializing your Inertia app](/guide/client-side-setup#configuring-defaults) to modify visit options globally for every request. The callback receives the target URL and the current visit options, and should return an object with any options you want to override. + +:::tabs key:frameworks +== Vue + +```js +import { createApp, h } from 'vue' +import { createInertiaApp } from '@inertiajs/vue3' + +createInertiaApp({ + // ... + defaults: { + visitOptions: (href, options) => { + return { + headers: { + ...options.headers, + 'X-Custom-Header': 'value', + }, + } + }, + }, +}) +``` + +== React + +```js +import { createInertiaApp } from '@inertiajs/react' +import { createRoot } from 'react-dom/client' + +createInertiaApp({ + // ... + defaults: { + visitOptions: (href, options) => { + return { + headers: { + ...options.headers, + 'X-Custom-Header': 'value', + }, + } + }, + }, +}) +``` + +== Svelte 4|Svelte 5 + +```js +import { createInertiaApp } from '@inertiajs/svelte' + +createInertiaApp({ + // ... + defaults: { + visitOptions: (href, options) => { + return { + headers: { + ...options.headers, + 'X-Custom-Header': 'value', + }, + } + }, + }, +}) +``` + +::: + ## File uploads When making visits / requests that include files, Inertia will automatically convert the request data into a `FormData` object. If you would like the request to always use a `FormData` object, you may use the `forceFormData` option. diff --git a/docs/guide/prefetching.md b/docs/guide/prefetching.md index d4e6b379..9c935f22 100644 --- a/docs/guide/prefetching.md +++ b/docs/guide/prefetching.md @@ -4,7 +4,7 @@ Inertia supports prefetching data for pages that are likely to be visited next. ## Link prefetching -To prefetch data for a page, you can add the `prefetch` prop to the Inertia link component. By default, Inertia will prefetch the data for the page when the user hovers over the link for more than 75ms. +To prefetch data for a page, you can add the `prefetch` prop to the Inertia link component. By default, Inertia will prefetch the data for the page when the user hovers over the link for more than 75ms. You may customize this hover delay by setting the `prefetch.hoverDelay` option in your [application defaults](/guide/client-side-setup#configuring-defaults). :::tabs key:frameworks == Vue @@ -43,7 +43,7 @@ export default () => ( ::: -By default, data is cached for 30 seconds before being evicted. You can customize this behavior by passing a `cacheFor` prop to the `Link` component. +By default, data is cached for 30 seconds before being evicted. You may customize this default value by setting the `prefetch.cacheFor` option in your [application defaults](/guide/client-side-setup#configuring-defaults). You may also customize the cache duration on a per-link basis by passing a `cacheFor` prop to the `Link` component. :::tabs key:frameworks == Vue diff --git a/docs/guide/title-and-meta.md b/docs/guide/title-and-meta.md index 28d73be9..92769442 100644 --- a/docs/guide/title-and-meta.md +++ b/docs/guide/title-and-meta.md @@ -347,3 +347,20 @@ export default () => ``` ::: + +## Inertia attribute on elements + +Inertia has historically used the `inertia` attribute to track and manage elements in the document ``. However, you can now opt-in to using the more standards-compliant `data-inertia` attribute instead. According to the HTML specification, custom attributes should be prefixed with `data-` to avoid conflicts with future HTML standards. + +To enable this, configure the `future.useDataInertiaHeadAttribute` option in your [application defaults](/guide/client-side-setup#configuring-defaults). + +```js +createInertiaApp({ + // resolve, setup, etc. + defaults: { + future: { + useDataInertiaHeadAttribute: true, + }, + }, +}) +``` From 965f540ef7684da6ddef6038508a6c8c604197da Mon Sep 17 00:00:00 2001 From: Svyatoslav Kryukov Date: Sat, 15 Nov 2025 00:24:00 +0300 Subject: [PATCH 2/5] Advise using defaultValue for Vue --- docs/guide/forms.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/forms.md b/docs/guide/forms.md index 5301a0fa..55ece8e3 100644 --- a/docs/guide/forms.md +++ b/docs/guide/forms.md @@ -151,7 +151,7 @@ You can pass a `transform` prop to modify the form data before submission. This ### Default values -You can set default values for form inputs using standard HTML attributes. Use `defaultValue``value``value``defaultValue` (`value` for Svelte < `5.6.0`) for text inputs and textareas, and `defaultChecked``checked``checked``defaultChecked` (`checked` for Svelte < `5.6.0`) for checkboxes and radios. +You can set default values for form inputs using standard HTML attributes. Use `defaultValue``defaultValue``value``defaultValue` (`value` for Svelte < `5.6.0`) for text inputs and textareas, and `defaultChecked``defaultChecked``checked``defaultChecked` (`checked` for Svelte < `5.6.0`) for checkboxes and radios. :::tabs key:frameworks @@ -160,7 +160,7 @@ You can set default values for form inputs using standard HTML attributes. Use < ```vue