diff --git a/docs/2.guide/2.directory-structure/1.components.md b/docs/2.guide/2.directory-structure/1.components.md index 331b254774..e50432e0d2 100644 --- a/docs/2.guide/2.directory-structure/1.components.md +++ b/docs/2.guide/2.directory-structure/1.components.md @@ -125,6 +125,16 @@ In real world applications, some pages may include a lot of content and a lot of In order to optimize the page, you may want to delay the hydration of some components until they're visible, or until the browser is done with more important tasks for example. Nuxt has first class support for delayed hydration components and can help you reduce your boilerplate along the way. +In order to use delayed hydration, you first need to enable it in your experimental config in `nuxt.config` + +```ts [nuxt.config.{ts,js}] +export default defineNuxtConfig({ + experimental: { + componentLazyHydration: true + } +}) +``` + Nuxt has reserved component prefixes that will handle this delayed hydration for you, that extend dynamic imports. By prefixing your component with `LazyVisible`, Nuxt will automatically handle your component and delay its hydration until it will be on screen. ```vue [pages/index.vue] @@ -145,6 +155,25 @@ If you need the component to load as soon as possible, but not block the critica ``` +### Custom hydration triggers + +If you would like to override the default hydration triggers when dealing with delayed hydration, like changing the timeout or the options for the intersection observer, you can do so by supplying a `loader` prop to your lazy components. + +```vue [pages/index.vue] + +``` + +::read-more{to="/docs/api/utils/create-idle-loader"} +:: + +::read-more{to="/docs/api/utils/create-visible-loader"} +:: + ::important Since Nuxt uses `LazyIdle` and `LazyVisible` to handle delayed hydration, you should avoid naming your components that, as dynamic imports will break for you. Delayed hydration would still be possible by adding the prefix, for example to a component named `IdleBar`: `` diff --git a/docs/3.api/3.utils/create-idle-loader.md b/docs/3.api/3.utils/create-idle-loader.md new file mode 100644 index 0000000000..8adbebe56f --- /dev/null +++ b/docs/3.api/3.utils/create-idle-loader.md @@ -0,0 +1,33 @@ +--- +title: 'createIdleLoader' +description: A utility function to customize delayed hydration based on network idle time. +links: + - label: Source + icon: i-simple-icons-github + to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/hydrate.ts + size: xs +--- + +You can use this utility to customize the timeout of delayed hydration components based on network idle time. + +## Parameters + +- `options`: `{ timeout }` + +## Example + +If you would like to give a timeout of 5 seconds for the components: + +```vue [pages/index.vue] +