From 91abe21fbf678852e9e5ac504c2f23e98a16a576 Mon Sep 17 00:00:00 2001 From: tbitw2549 Date: Fri, 8 Nov 2024 23:13:04 +0200 Subject: [PATCH] refactor: build plugin with prop based approach --- .../2.directory-structure/1.components.md | 70 ++++++++----------- packages/nuxt/src/components/module.ts | 7 +- .../components/plugins/delayed-hydration.ts | 35 ++++++++++ .../nuxt/src/components/plugins/loader.ts | 17 +++-- packages/nuxt/src/components/templates.ts | 22 +----- .../pages/lazy-import-components/index.vue | 30 ++++---- .../lazy-import-components/model-event.vue | 3 +- .../pages/lazy-import-components/promise.vue | 8 +-- .../pages/lazy-import-components/time.vue | 6 +- 9 files changed, 110 insertions(+), 88 deletions(-) create mode 100644 packages/nuxt/src/components/plugins/delayed-hydration.ts diff --git a/docs/2.guide/2.directory-structure/1.components.md b/docs/2.guide/2.directory-structure/1.components.md index 72e024e53..2e99d1d1d 100644 --- a/docs/2.guide/2.directory-structure/1.components.md +++ b/docs/2.guide/2.directory-structure/1.components.md @@ -139,84 +139,84 @@ export default defineNuxtConfig({ }) ``` -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. +Nuxt has reserved component properties that will handle this delayed hydration for you, that extend dynamic imports. By using the `hydrate:visible` prop, Nuxt will automatically handle your component and delay its hydration until it will be on screen. ```vue [pages/index.vue] ``` -If you need the component to load as soon as possible, but not block the critical rendering path, you can use the `LazyIdle` prefix, which would handle your component's hydration whenever the browser goes idle. +If you need the component to load as soon as possible, but not block the critical rendering path, you can use the `hdrate:idle` prop, which would handle your component's hydration whenever the browser goes idle. ```vue [pages/index.vue] ``` -If you would like the component to load after certain events occur, like a click or a mouse over, you can use the `LazyEvent` prefix, which would only trigger the hydration when those events occur. +If you would like the component to load after certain events occur, like a click or a mouse over, you can use the `hydrate:event` prop, which would only trigger the hydration when those events occur. ```vue [pages/index.vue] ``` -If you would like to load the component when the window matches a media query, you can use the `LazyMedia` prefix: +If you would like to load the component when the window matches a media query, you can use the `hydrate:media` prop: ```vue [pages/index.vue] ``` -If you would like to never hydrate a component, use the `LazyNever` prefix: +If you would like to never hydrate a component, use the `hydrate:never` prop: ```vue [pages/index.vue] ``` -If you would like to hydrate a component after a certain amount of time, use the `LazyTime` prefix: +If you would like to hydrate a component after a certain amount of time, use the `hydrate:time` prop: ```vue [pages/index.vue] ``` -If you would like to hydrate a component once a promise is fulfilled, use the `LazyPromise` prefix: +If you would like to hydrate a component once a promise is fulfilled, use the `hydrate:promise` prefix: ```vue [pages/index.vue] ``` Nuxt's delayed hydration system is highly flexible, allowing each developer to build upon it and implement their own hydration strategy. -If you have highly specific hydration triggers that aren't covered by the default strategies, or you want to have conditional hydration, you can use the general purpose `LazyIf` prefix: +If you have highly specific hydration triggers that aren't covered by the default strategies, or you want to have conditional hydration, you can use the general purpose `hydrate:if` prop: ```vue [pages/index.vue]