mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
Compare commits
305 Commits
128e280563
...
c75f5a0d76
Author | SHA1 | Date | |
---|---|---|---|
|
c75f5a0d76 | ||
|
edc299a043 | ||
|
ad3ab4d310 | ||
|
6479a91928 | ||
|
3bd2bf7cf7 | ||
|
41a15205fd | ||
|
0c9dcb9f66 | ||
|
91abe21fbf | ||
|
897b067e19 | ||
|
b2b2c4db63 | ||
|
7c6b5d73c7 | ||
|
d3aef5549a | ||
|
d81740d439 | ||
|
725727f397 | ||
|
352d47c644 | ||
|
c4123fa09f | ||
|
bd831cac14 | ||
|
beedda3f2a | ||
|
f054daccf8 | ||
|
cd7cc48ca3 | ||
|
59392c7f7e | ||
|
100664e149 | ||
|
6945776b6c | ||
|
6c741f7cad | ||
|
0bed244f5c | ||
|
bf131a2173 | ||
|
c0844b902e | ||
|
373e223268 | ||
|
70b7739739 | ||
|
c39bad01e2 | ||
|
1ad62a16f5 | ||
|
6f1757700c | ||
|
fe9b2b96f5 | ||
|
86384794e8 | ||
|
3ced1449e6 | ||
|
1429c11394 | ||
|
2d2074a927 | ||
|
e068873e6e | ||
|
4e469b7de5 | ||
|
87cd1048ca | ||
|
311ac8ad93 | ||
|
5cc422b820 | ||
|
8b95e4e05a | ||
|
a9c76a405c | ||
|
fb6d4a518a | ||
|
c32834fc2e | ||
|
07c7f2ca92 | ||
|
889a5642fb | ||
|
74231878ea | ||
|
67d3cadcb2 | ||
|
124d1e2b49 | ||
|
5e973777b7 | ||
|
f0c492a657 | ||
|
e304d6c367 | ||
|
7fc29e1a56 | ||
|
1794ae33f1 | ||
|
62fb11f253 | ||
|
31779d2371 | ||
|
309726060c | ||
|
1a1fe463df | ||
|
60a34552cc | ||
|
47e2443a37 | ||
|
784c34fc91 | ||
|
f3f594f7f9 | ||
|
3426fca610 | ||
|
b64dca110e | ||
|
cafc328ef2 | ||
|
8d066205c2 | ||
|
b9b25a6e41 | ||
|
2df3351048 | ||
|
52789fa47a | ||
|
3d88fce4c7 | ||
|
0e4e92b716 | ||
|
6803f61667 | ||
|
9060907f3f | ||
|
b28ee7896d | ||
|
e7621cb222 | ||
|
97fd06e4ff | ||
|
70789a0631 | ||
|
9456f3f12e | ||
|
a80843f9d2 | ||
|
9cbdbc7814 | ||
|
d80c5562b7 | ||
|
f47b0d6c4e | ||
|
0919a82a75 | ||
|
5cb4e41553 | ||
|
0046959bf3 | ||
|
0f79d798e9 | ||
|
b36d0b484e | ||
|
bfb875e1fe | ||
|
66c831bd41 | ||
|
8344e87dc8 | ||
|
0585f8aba0 | ||
|
b21f88e5da | ||
|
24fdcda7d4 | ||
|
51f20645d9 | ||
|
cd7e85842c | ||
|
38fabb56e6 | ||
|
7025412d35 | ||
|
022b836cdc | ||
|
b749509f9d | ||
|
d54e58dc44 | ||
|
794f46114f | ||
|
5124ebe4d1 | ||
|
768ebe4591 | ||
|
3f11337999 | ||
|
36ffef9fa5 | ||
|
e2416801e4 | ||
|
7f51c8a133 | ||
|
6cb16f41cf | ||
|
ee6cd61e2d | ||
|
1fbe165da5 | ||
|
7bdfc6cc86 | ||
|
86e88052fc | ||
|
34d13cbe0e | ||
|
945a225d78 | ||
|
b72e45ef9e | ||
|
751e5f8194 | ||
|
f8f752fc74 | ||
|
587a5dbce0 | ||
|
3727a435b5 | ||
|
5d5432cba7 | ||
|
aa3df0bc6f | ||
|
b8c36774f5 | ||
|
76a267de4d | ||
|
cf9a905993 | ||
|
0ab38fcd09 | ||
|
e12d4b13ee | ||
|
5390cae241 | ||
|
d5bd5f8392 | ||
|
76f2f5dc4a | ||
|
06096dcc0c | ||
|
e3a0242048 | ||
|
9ba1682eba | ||
|
0c8672bc62 | ||
|
1cb243ed08 | ||
|
d556ac26f7 | ||
|
4a1c1f5969 | ||
|
fa0bdc0e5b | ||
|
068d40a283 | ||
|
52e55ee044 | ||
|
64179576b5 | ||
|
85c1ac8266 | ||
|
1c883b983e | ||
|
d6e475ec0d | ||
|
9cec31ea49 | ||
|
d520d347f2 | ||
|
dbdb3fe6a1 | ||
|
712f81390d | ||
|
3602fe1947 | ||
|
2021eac17b | ||
|
c2e22c60e9 | ||
|
0ead860117 | ||
|
8c522836ed | ||
|
23d0b8e4c8 | ||
|
c14580d8c1 | ||
|
0b769781c5 | ||
|
da1db599cc | ||
|
0732872d74 | ||
|
6e6832fc3e | ||
|
09489b9d7a | ||
|
10e9d00fa4 | ||
|
6be28279f1 | ||
|
0792f95b86 | ||
|
fb3397701e | ||
|
2fd3aa422f | ||
|
09f341c3ef | ||
|
2089f745a8 | ||
|
7ad6b06809 | ||
|
1039735d45 | ||
|
2b765e0b88 | ||
|
53c8bb92fe | ||
|
ed16dc4a7d | ||
|
b0f4f64d27 | ||
|
c8cbcfc56e | ||
|
53d73baa48 | ||
|
79a805fa8c | ||
|
b9e7354241 | ||
|
ee7d8fa20e | ||
|
b87a70c825 | ||
|
86e7c44ca5 | ||
|
4442d5f294 | ||
|
a80536d4c0 | ||
|
6fa4dd2807 | ||
|
6e4f05d31d | ||
|
7137a7b3b5 | ||
|
afa2e9aedf | ||
|
4eb39d1062 | ||
|
b764ae93be | ||
|
2f2cb8e0cf | ||
|
e0a2f219db | ||
|
a53c5897a1 | ||
|
ea0dea2a49 | ||
|
440f4cc91a | ||
|
a0f43b45f2 | ||
|
502383feea | ||
|
046c1ce85f | ||
|
9746137b28 | ||
|
f4f8ca08dc | ||
|
d32cfdf09b | ||
|
a26603fafb | ||
|
90fb0d5904 | ||
|
6d3ec1714b | ||
|
5051c861b1 | ||
|
2a244f056f | ||
|
66dd659821 | ||
|
28647ecb30 | ||
|
41c4b53af7 | ||
|
d04d244799 | ||
|
b1c498bea7 | ||
|
b143038cef | ||
|
6f806878fd | ||
|
f5937803f8 | ||
|
2ac90f37b6 | ||
|
4616c172e0 | ||
|
b1e66e5c05 | ||
|
fa46fe3e4f | ||
|
3076e02082 | ||
|
d65d3174b8 | ||
|
ad6bef5f70 | ||
|
b45c3c9cae | ||
|
850287bf18 | ||
|
0cb15c6bbd | ||
|
8eaf057ffe | ||
|
9b8d33babf | ||
|
13949edeb3 | ||
|
fd0adea179 | ||
|
162908aac0 | ||
|
7821e7f441 | ||
|
1f196a57cd | ||
|
5c300a4698 | ||
|
e4c9940269 | ||
|
cfb6660fcd | ||
|
cb7fc3f873 | ||
|
8555cec97d | ||
|
2ee3cf53ee | ||
|
dc6d922773 | ||
|
e2d0350698 | ||
|
580d9bd463 | ||
|
31002ecc2d | ||
|
2375650c36 | ||
|
b4c4d47721 | ||
|
effebbb02f | ||
|
2df20ac681 | ||
|
503b560d9b | ||
|
817c3ace86 | ||
|
382bc93efe | ||
|
717a91c10a | ||
|
45e49c5beb | ||
|
8c1c23a422 | ||
|
b3250e4a46 | ||
|
d4bca6cd57 | ||
|
59edd16fce | ||
|
3a8b1f3b75 | ||
|
9b94d100a2 | ||
|
669fcee81b | ||
|
2fa63ccfff | ||
|
988a99b771 | ||
|
26f2e4e7d1 | ||
|
5653d9e255 | ||
|
bd7ca85fb4 | ||
|
dd36a18140 | ||
|
36dc73152f | ||
|
2236f78566 | ||
|
4b0d88c54e | ||
|
d89e70e065 | ||
|
84b2333cf5 | ||
|
10f7f22c82 | ||
|
00a68bd7ff | ||
|
88bae15ad7 | ||
|
d209a02492 | ||
|
4cc9efe563 | ||
|
998c1ba551 | ||
|
6c683e0b6e | ||
|
816ba111b4 | ||
|
20a32b2200 | ||
|
66938bc152 | ||
|
758824463d | ||
|
444e5be6e8 | ||
|
8d435a1f45 | ||
|
9713e32f07 | ||
|
586cfa5a3e | ||
|
36f2c75290 | ||
|
600f55d2a3 | ||
|
0caf8153ea | ||
|
1e16b4a088 | ||
|
f6ba2255e6 | ||
|
966c17be72 | ||
|
caf73523c8 | ||
|
b3b1676202 | ||
|
f51c9362ce | ||
|
7d2f345511 | ||
|
f039dfd09f | ||
|
624188a7cf | ||
|
85b4d6932b | ||
|
d94436b9c4 | ||
|
2ac2a975e0 | ||
|
cb221ed579 | ||
|
932d143688 | ||
|
6a32dc1c9e | ||
|
ae2bb27ac0 | ||
|
84b0a71b8c | ||
|
9ac1261662 | ||
|
d64d78fde8 | ||
|
9f629ad45a |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -248,7 +248,7 @@ jobs:
|
|||||||
TEST_PAYLOAD: ${{ matrix.payload }}
|
TEST_PAYLOAD: ${{ matrix.payload }}
|
||||||
SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }}
|
SKIP_BUNDLE_SIZE: ${{ github.event_name != 'push' || matrix.env == 'dev' || matrix.builder == 'webpack' || matrix.context == 'default' || matrix.payload == 'js' || runner.os == 'Windows' }}
|
||||||
|
|
||||||
- uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
|
- uses: codecov/codecov-action@985343d70564a82044c1b7fcb84c2fa05405c1a2 # v5.0.4
|
||||||
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
|
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
@ -123,6 +123,176 @@ const show = ref(false)
|
|||||||
</template>
|
</template>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Delayed Hydration
|
||||||
|
|
||||||
|
Lazy components are great for controlling the chunk sizes in your app, but they don't enhance runtime performance, as they still load eagerly unless conditionally rendered. In real world applications, some pages may include a lot of content and a lot of components, and most of the time not all of them need to be interactive as soon as the page is loaded. Having them all load eagerly can negatively impact performance and increase bundle size.
|
||||||
|
|
||||||
|
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. Delaying the hydration of components will ensure it is only loaded when necessary, which is great for making a good user experience and a performant app. Nuxt has first class support for delayed hydration to help with that, without requiring you to write all the related boilerplate.
|
||||||
|
|
||||||
|
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: {
|
||||||
|
delayedHydration: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
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]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:visible />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
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]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:idle />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
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]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:event />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
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]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:media />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you would like to never hydrate a component, use the `hydrate:never` prop:
|
||||||
|
|
||||||
|
```vue [pages/index.vue]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:never />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you would like to hydrate a component after a certain amount of time, use the `hydrate:time` prop:
|
||||||
|
|
||||||
|
```vue [pages/index.vue]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:time />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you would like to hydrate a component once a promise is fulfilled, use the `hydrate:promise` prefix:
|
||||||
|
|
||||||
|
```vue [pages/index.vue]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:promise />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
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 `hydrate:if` prop:
|
||||||
|
|
||||||
|
```vue [pages/index.vue]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<button @click="myFunction">Click me to start the custom hydration strategy</button>
|
||||||
|
<LazyMyComponent :hydrate:if="myCondition" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
const myCondition = ref(false)
|
||||||
|
function myFunction() {
|
||||||
|
// trigger custom hydration strategy...
|
||||||
|
myCondition.value = true
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom hydration triggers
|
||||||
|
|
||||||
|
If you would like to override the default hydration triggers when dealing with delayed hydration, like changing the timeout, the options for the intersection observer, or the events to trigger the hydration, you can do so by supplying a value to the respetive props of your lazy components.
|
||||||
|
|
||||||
|
```vue [pages/index.vue]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent :hydrate:idle="3000" />
|
||||||
|
<LazyMyComponent :hydrate:visible="{threshold: 0.2}" />
|
||||||
|
<LazyMyComponent :hydrate:event="['click','mouseover']" />
|
||||||
|
<LazyMyComponent hydrate:media="(max-width: 500px)" />
|
||||||
|
<LazyMyComponent :hydrate:if="someCondition" />
|
||||||
|
<LazyMyComponent :hydrate:time="3000" />
|
||||||
|
<LazyMyComponent :hydrate:promise="promise" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const someCondition = ref(true)
|
||||||
|
const promise = Promise.resolve(42)
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
::read-more{to="https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia"}
|
||||||
|
Read more about using `LazyMedia` components and the accepted values.
|
||||||
|
::
|
||||||
|
|
||||||
|
### Listening to hydration events
|
||||||
|
|
||||||
|
All delayed hydration components have a `@hydrated` event that is fired whenever they are hydrated. You can listen to this event to trigger some action that depends on the component:
|
||||||
|
|
||||||
|
```vue [pages/index.vue]
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyMyComponent hydrate:visible @hydrated="onHydrate" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
function onHydrate() {
|
||||||
|
console.log("Component has been hydrated!")
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Caveats and best practices
|
||||||
|
|
||||||
|
Delayed hydration has many performance benefits, but in order to gain the most out of it, it's important to use it correctly:
|
||||||
|
|
||||||
|
1. Avoid delayed hydration components as much as possible for in-viewport content - delayed hydration is best for content that is not immediately available and requires some interaction to get to. If it is present on screen and is meant to be available for use immediately, using it as a normal component would provide better performance and loading times. Use this feature sparingly to avoid hurting the user experience, as there are only a few cases that warrant delayed hydration for on-screen content.
|
||||||
|
|
||||||
|
2. Delayed hydration with conditional rendering - when using `v-if` with delayed hydration components, note that `v-if` takes precedence. That means, the component will be hydrated when the `v-if` is truthy, as that will render exclusively on the client. If you need to render the component only when the condition is true, use a regular async component (`<LazyMyComponent />`) with a `v-if`. If you need it to hydrate when the condition is fulfilled, use a delayed hydration prop.
|
||||||
|
|
||||||
|
3. Delayed hydration with a shared state - when using multiple components (for example, in a `v-for`) with the same `v-model`, where some components might get hydrated before others (for example, progressively increasing media queries), if one of the components updates the model, note that it will trigger hydration for all components with that same model. That is because Vue's reactivity system triggers an update for all the parts of the app that depend on that state, forcing hydration in the process. Props are unaffected by this. Try to avoid multiple components with the same model if that is not an intended side effect.
|
||||||
|
|
||||||
|
4. Use each hydration strategy for its intended use case - each hydration strategy has built-in optimizations specifically designed for that strategy's purpose. Using them incorrectly could hurt performance and user experience. Examples include:
|
||||||
|
|
||||||
|
- Using `hydrate:if` for always/never hydrated components (`:hydrate:if="true"`/`:hydrate:if="false"`) - you can use a regular component/`hydrate:never` respectively, which would provide better performance for each use case. Keep `LazyIf` for components that could get hydrated, but might not get hydrated immediately.
|
||||||
|
|
||||||
|
- Using `hydrate:time` as an alternative to `hydrate:idle` - while these strategies share similarities, they are meant for different purposes. `hydrate:time` is specifically designed to hydrate a component immediately after a certain amount of time has passed. `hydrate:idle`, on the other hand, is meant to provide a limit for the browser to handle the hydration whenever it's idle. If you use `hydrate:time` for idle-based hydration, the browser might handle the component's hydration while handling other, potentially more important components at the same time. This could slow down the hydration for all components being handled.
|
||||||
|
|
||||||
|
- \[ADVANCED\] Using only `hydrate:if` to manually implement existing hydration strategies - while an option, using only `hydrate:if` in stead of relying on the built-in supported strategies could impact the overall memory consumption and performance.
|
||||||
|
For example, in stead of handling promises manually and setting a boolean indicator for when the promise was fulfilled, which would then get passed to `hydrate:if`, using `hydrate:promise` directly would handle it without requiring another ref, reducing the complexity and the amount of work Vue's reactivity system would need to handle and track.
|
||||||
|
Always remember that while `hydrate:if` allows for implementation of custom, highly-tailored hydration strategies, it should mainly be used when either pure conditional hydration is required (for example, hydration of a component when a separate button is clicked), or when no built-in strategy matches your specific use case, due to the internal optimizations each existing hydration strategy has.
|
||||||
|
|
||||||
## Direct Imports
|
## Direct Imports
|
||||||
|
|
||||||
You can also explicitly import components from `#components` if you want or need to bypass Nuxt's auto-importing functionality.
|
You can also explicitly import components from `#components` if you want or need to bypass Nuxt's auto-importing functionality.
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
"devalue": "5.1.1",
|
"devalue": "5.1.1",
|
||||||
"eslint": "9.15.0",
|
"eslint": "9.15.0",
|
||||||
"eslint-plugin-no-only-tests": "3.3.0",
|
"eslint-plugin-no-only-tests": "3.3.0",
|
||||||
"eslint-plugin-perfectionist": "4.0.2",
|
"eslint-plugin-perfectionist": "4.0.3",
|
||||||
"eslint-typegen": "0.3.2",
|
"eslint-typegen": "0.3.2",
|
||||||
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
|
||||||
"happy-dom": "15.11.6",
|
"happy-dom": "15.11.6",
|
||||||
@ -118,7 +118,7 @@
|
|||||||
"vue-router": "4.4.5",
|
"vue-router": "4.4.5",
|
||||||
"vue-tsc": "2.1.10"
|
"vue-tsc": "2.1.10"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.13.2",
|
"packageManager": "pnpm@9.14.1",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^16.10.0 || >=18.0.0"
|
"node": "^16.10.0 || >=18.0.0"
|
||||||
},
|
},
|
||||||
|
@ -481,7 +481,7 @@ type CallbackFn = () => void
|
|||||||
type ObserveFn = (element: Element, callback: CallbackFn) => () => void
|
type ObserveFn = (element: Element, callback: CallbackFn) => () => void
|
||||||
|
|
||||||
function useObserver (): { observe: ObserveFn } | undefined {
|
function useObserver (): { observe: ObserveFn } | undefined {
|
||||||
if (import.meta.server) { return }
|
if (import.meta.server) { return { observe: () => () => {} } }
|
||||||
|
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
if (nuxtApp._observer) {
|
if (nuxtApp._observer) {
|
||||||
@ -489,7 +489,6 @@ function useObserver (): { observe: ObserveFn } | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let observer: IntersectionObserver | null = null
|
let observer: IntersectionObserver | null = null
|
||||||
|
|
||||||
const callbacks = new Map<Element, CallbackFn>()
|
const callbacks = new Map<Element, CallbackFn>()
|
||||||
|
|
||||||
const observe: ObserveFn = (element, callback) => {
|
const observe: ObserveFn = (element, callback) => {
|
||||||
|
@ -13,6 +13,7 @@ import { ComponentsChunkPlugin, IslandsTransformPlugin } from './plugins/islands
|
|||||||
import { TransformPlugin } from './plugins/transform'
|
import { TransformPlugin } from './plugins/transform'
|
||||||
import { TreeShakeTemplatePlugin } from './plugins/tree-shake'
|
import { TreeShakeTemplatePlugin } from './plugins/tree-shake'
|
||||||
import { ComponentNamePlugin } from './plugins/component-names'
|
import { ComponentNamePlugin } from './plugins/component-names'
|
||||||
|
import { DelayedHydrationPlugin } from './plugins/delayed-hydration'
|
||||||
|
|
||||||
const isPureObjectOrString = (val: any) => (!Array.isArray(val) && typeof val === 'object') || typeof val === 'string'
|
const isPureObjectOrString = (val: any) => (!Array.isArray(val) && typeof val === 'object') || typeof val === 'string'
|
||||||
const isDirectory = (p: string) => { try { return statSync(p).isDirectory() } catch { return false } }
|
const isDirectory = (p: string) => { try { return statSync(p).isDirectory() } catch { return false } }
|
||||||
@ -223,13 +224,17 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
addBuildPlugin(ClientFallbackAutoIdPlugin({ sourcemap: !!nuxt.options.sourcemap.server, rootDir: nuxt.options.rootDir }), { client: false })
|
addBuildPlugin(ClientFallbackAutoIdPlugin({ sourcemap: !!nuxt.options.sourcemap.server, rootDir: nuxt.options.rootDir }), { client: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clientDelayedComponentRuntime = await findPath(join(distDir, 'components/runtime/client-delayed-component')) ?? join(distDir, 'components/runtime/client-delayed-component')
|
||||||
const sharedLoaderOptions = {
|
const sharedLoaderOptions = {
|
||||||
getComponents,
|
getComponents,
|
||||||
serverComponentRuntime,
|
serverComponentRuntime,
|
||||||
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
|
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
|
||||||
experimentalComponentIslands: !!nuxt.options.experimental.componentIslands,
|
experimentalComponentIslands: !!nuxt.options.experimental.componentIslands,
|
||||||
|
clientDelayedComponentRuntime,
|
||||||
|
}
|
||||||
|
if (nuxt.options.experimental.delayedHydration) {
|
||||||
|
addBuildPlugin(DelayedHydrationPlugin({ sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client }))
|
||||||
}
|
}
|
||||||
|
|
||||||
addBuildPlugin(LoaderPlugin({ ...sharedLoaderOptions, sourcemap: !!nuxt.options.sourcemap.client, mode: 'client' }), { server: false })
|
addBuildPlugin(LoaderPlugin({ ...sharedLoaderOptions, sourcemap: !!nuxt.options.sourcemap.client, mode: 'client' }), { server: false })
|
||||||
addBuildPlugin(LoaderPlugin({ ...sharedLoaderOptions, sourcemap: !!nuxt.options.sourcemap.server, mode: 'server' }), { client: false })
|
addBuildPlugin(LoaderPlugin({ ...sharedLoaderOptions, sourcemap: !!nuxt.options.sourcemap.server, mode: 'server' }), { client: false })
|
||||||
|
|
||||||
|
35
packages/nuxt/src/components/plugins/delayed-hydration.ts
Normal file
35
packages/nuxt/src/components/plugins/delayed-hydration.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { createUnplugin } from 'unplugin'
|
||||||
|
import { logger } from '@nuxt/kit'
|
||||||
|
import MagicString from 'magic-string'
|
||||||
|
import { isVue } from '../../core/utils'
|
||||||
|
|
||||||
|
export const DelayedHydrationPlugin = (options: { sourcemap: boolean }) => createUnplugin(() => {
|
||||||
|
const DELAYED_HYDRATION_RE = /<(?:Lazy|lazy-)([A-Z]\w*|[\w-]+)\b([^>]+)hydrate:(\w+)(="([^"]+)")?([ />])([^>]*(?:(?<=\/)|>[\s\S]+?<\/Lazy[A-Z]\w*|lazy-[\w-]+))>/g
|
||||||
|
const types = new Map([['time', 'Time'], ['promise', 'Promise'], ['if', 'If'], ['event', 'Event'], ['visible', 'Visible'], ['media', 'Media'], ['never', 'Never'], ['idle', 'Idle']])
|
||||||
|
const correctVals = new Map([['time', 'number'], ['promise', 'Promise'], ['event', 'string | string[]'], ['visible', 'IntersectionObserverInit'], ['media', 'string'], ['idle', 'number']])
|
||||||
|
return {
|
||||||
|
name: 'nuxt:delayed-hydration',
|
||||||
|
enforce: 'pre',
|
||||||
|
transformInclude (id) {
|
||||||
|
return isVue(id)
|
||||||
|
},
|
||||||
|
transform (code, id) {
|
||||||
|
const s = new MagicString(code)
|
||||||
|
s.replace(DELAYED_HYDRATION_RE, (_, comp, pre, type, selfOrValue, val, nearEndChar, post) => {
|
||||||
|
const shouldDefault = type !== 'if' && (val === 'true' || val === 'false')
|
||||||
|
if (!types.has(type)) { logger.warn(`Unexpected hydration strategy \`${type}\` when parsing \`${_}\` in \`${id}\`, this will default to visibility. For custom strategies, please use \`v-hydrate:if\` in stead.`) }
|
||||||
|
if (type === 'never' && selfOrValue) { logger.warn('`hydrate:never` does not accept any value. It is meant to be used as is, and the value will not affect its runtime behavior.') }
|
||||||
|
if (shouldDefault) { logger.warn(`Invalid value \`${val}\` for \`hydrate:${type}\` when parsing \`${_}\` in \`${id}\`. The prop is not meant to be assigned a boolean, but used as is or given ${type === 'never' ? 'no value' : `a value of type \`${correctVals.get(type) ?? 'unknown'}\``}. This will not affect runtime behavior and the defaults will be used in stead.`) }
|
||||||
|
return `<Lazy${types.get(type) ?? 'Visible'}${comp}${pre}${type == 'never' || shouldDefault ? '' : `:hydrate="${val}"`}${nearEndChar}${post}>`
|
||||||
|
})
|
||||||
|
if (s.hasChanged()) {
|
||||||
|
return {
|
||||||
|
code: s.toString(),
|
||||||
|
map: options.sourcemap
|
||||||
|
? s.generateMap({ hires: true })
|
||||||
|
: undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
@ -12,12 +12,13 @@ interface LoaderOptions {
|
|||||||
getComponents (): Component[]
|
getComponents (): Component[]
|
||||||
mode: 'server' | 'client'
|
mode: 'server' | 'client'
|
||||||
serverComponentRuntime: string
|
serverComponentRuntime: string
|
||||||
|
clientDelayedComponentRuntime: string
|
||||||
sourcemap?: boolean
|
sourcemap?: boolean
|
||||||
transform?: ComponentsOptions['transform']
|
transform?: ComponentsOptions['transform']
|
||||||
experimentalComponentIslands?: boolean
|
experimentalComponentIslands?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const REPLACE_COMPONENT_TO_DIRECT_IMPORT_RE = /(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy(?=[A-Z]))?([^'"]*)["'][^)]*\)/g
|
const REPLACE_COMPONENT_TO_DIRECT_IMPORT_RE = /(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy(?=[A-Z]))?(Idle|Visible|idle-|visible-|Event|event-|Media|media-|If|if-|Never|never-|Time|time-|Promise|promise-)?([^'"]*)["'][^)]*\)/g
|
||||||
export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
||||||
const exclude = options.transform?.exclude || []
|
const exclude = options.transform?.exclude || []
|
||||||
const include = options.transform?.include || []
|
const include = options.transform?.include || []
|
||||||
@ -42,12 +43,13 @@ export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
|||||||
const imports = new Set<string>()
|
const imports = new Set<string>()
|
||||||
const map = new Map<Component, string>()
|
const map = new Map<Component, string>()
|
||||||
const s = new MagicString(code)
|
const s = new MagicString(code)
|
||||||
|
|
||||||
// replace `_resolveComponent("...")` to direct import
|
// replace `_resolveComponent("...")` to direct import
|
||||||
s.replace(REPLACE_COMPONENT_TO_DIRECT_IMPORT_RE, (full: string, lazy: string, name: string) => {
|
s.replace(REPLACE_COMPONENT_TO_DIRECT_IMPORT_RE, (full: string, lazy: string, modifier: string, name: string) => {
|
||||||
const component = findComponent(components, name, options.mode)
|
const normalComponent = findComponent(components, name, options.mode)
|
||||||
|
const modifierComponent = !normalComponent && modifier ? findComponent(components, modifier + name, options.mode) : null
|
||||||
|
const component = normalComponent || modifierComponent
|
||||||
|
|
||||||
if (component) {
|
if (component) {
|
||||||
// TODO: refactor to nuxi
|
|
||||||
const internalInstall = ((component as any)._internal_install) as string
|
const internalInstall = ((component as any)._internal_install) as string
|
||||||
if (internalInstall && nuxt?.options.test === false) {
|
if (internalInstall && nuxt?.options.test === false) {
|
||||||
if (!nuxt.options.dev) {
|
if (!nuxt.options.dev) {
|
||||||
@ -77,9 +79,63 @@ export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lazy) {
|
if (lazy) {
|
||||||
|
const dynamicImport = `${genDynamicImport(component.filePath, { interopDefault: false })}.then(c => c.${component.export ?? 'default'} || c)`
|
||||||
|
if (modifier && normalComponent && nuxt?.options.experimental.delayedHydration === true) {
|
||||||
|
switch (modifier) {
|
||||||
|
case 'Visible':
|
||||||
|
case 'visible-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyIOComponent' }]))
|
||||||
|
identifier += '_delayedIO'
|
||||||
|
imports.add(`const ${identifier} = createLazyIOComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
case 'Event':
|
||||||
|
case 'event-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyEventComponent' }]))
|
||||||
|
identifier += '_delayedEvent'
|
||||||
|
imports.add(`const ${identifier} = createLazyEventComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
case 'Idle':
|
||||||
|
case 'idle-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyNetworkComponent' }]))
|
||||||
|
identifier += '_delayedNetwork'
|
||||||
|
imports.add(`const ${identifier} = createLazyNetworkComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
case 'Media':
|
||||||
|
case 'media-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyMediaComponent' }]))
|
||||||
|
identifier += '_delayedMedia'
|
||||||
|
imports.add(`const ${identifier} = createLazyMediaComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
case 'If':
|
||||||
|
case 'if-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyIfComponent' }]))
|
||||||
|
identifier += '_delayedIf'
|
||||||
|
imports.add(`const ${identifier} = createLazyIfComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
case 'Never':
|
||||||
|
case 'never-':
|
||||||
|
imports.add(genImport('vue', [{ name: 'defineAsyncComponent', as: '__defineAsyncComponent' }]))
|
||||||
|
identifier += '_delayedNever'
|
||||||
|
imports.add(`const ${identifier} = __defineAsyncComponent({loader: ${dynamicImport}, hydrate: () => {}})`)
|
||||||
|
break
|
||||||
|
case 'Time':
|
||||||
|
case 'time-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyTimeComponent' }]))
|
||||||
|
identifier += '_delayedTime'
|
||||||
|
imports.add(`const ${identifier} = createLazyTimeComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
case 'Promise':
|
||||||
|
case 'promise-':
|
||||||
|
imports.add(genImport(options.clientDelayedComponentRuntime, [{ name: 'createLazyPromiseComponent' }]))
|
||||||
|
identifier += '_delayedPromise'
|
||||||
|
imports.add(`const ${identifier} = createLazyPromiseComponent(${dynamicImport})`)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
imports.add(genImport('vue', [{ name: 'defineAsyncComponent', as: '__defineAsyncComponent' }]))
|
imports.add(genImport('vue', [{ name: 'defineAsyncComponent', as: '__defineAsyncComponent' }]))
|
||||||
identifier += '_lazy'
|
identifier += '_lazy'
|
||||||
imports.add(`const ${identifier} = __defineAsyncComponent(${genDynamicImport(component.filePath, { interopDefault: false })}.then(c => c.${component.export ?? 'default'} || c)${isClientOnly ? '.then(c => createClientOnly(c))' : ''})`)
|
imports.add(`const ${identifier} = __defineAsyncComponent(${dynamicImport}${isClientOnly ? '.then(c => createClientOnly(c))' : ''})`)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
imports.add(genImport(component.filePath, [{ name: component._raw ? 'default' : component.export, as: identifier }]))
|
imports.add(genImport(component.filePath, [{ name: component._raw ? 'default' : component.export, as: identifier }]))
|
||||||
|
|
||||||
|
175
packages/nuxt/src/components/runtime/client-delayed-component.ts
Normal file
175
packages/nuxt/src/components/runtime/client-delayed-component.ts
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
import { defineAsyncComponent, defineComponent, h, hydrateOnIdle, hydrateOnInteraction, hydrateOnMediaQuery, hydrateOnVisible, mergeProps, watch } from 'vue'
|
||||||
|
import type { AsyncComponentLoader, HydrationStrategy } from 'vue'
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyIOComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: Object,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: hydrateOnVisible(props.hydrate as IntersectionObserverInit | undefined) })
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyNetworkComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: Number,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
if (props.hydrate === 0) {
|
||||||
|
const comp = defineAsyncComponent(loader)
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
}
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: hydrateOnIdle(props.hydrate) })
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyEventComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: [String, Array],
|
||||||
|
required: false,
|
||||||
|
default: 'mouseover',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
// @ts-expect-error Cannot type HTMLElementEventMap in props
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: hydrateOnInteraction(props.hydrate) })
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyMediaComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
default: '(min-width: 1px)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: hydrateOnMediaQuery(props.hydrate) })
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyIfComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
if (props.hydrate) {
|
||||||
|
const comp = defineAsyncComponent(loader)
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
}
|
||||||
|
const strategy: HydrationStrategy = (hydrate) => {
|
||||||
|
const unwatch = watch(() => props.hydrate, () => hydrate(), { once: true })
|
||||||
|
return () => unwatch()
|
||||||
|
}
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: strategy })
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyTimeComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: Number,
|
||||||
|
required: false,
|
||||||
|
default: 2000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
if (props.hydrate === 0) {
|
||||||
|
const comp = defineAsyncComponent(loader)
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
}
|
||||||
|
const strategy: HydrationStrategy = (hydrate) => {
|
||||||
|
const id = setTimeout(hydrate, props.hydrate)
|
||||||
|
return () => clearTimeout(id)
|
||||||
|
}
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: strategy })
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export const createLazyPromiseComponent = (loader: AsyncComponentLoader) => {
|
||||||
|
return defineComponent({
|
||||||
|
inheritAttrs: false,
|
||||||
|
props: {
|
||||||
|
hydrate: {
|
||||||
|
type: Promise,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emits: ['hydrated'],
|
||||||
|
setup (props, { attrs, emit }) {
|
||||||
|
const hydrated = () => { emit('hydrated') }
|
||||||
|
if (!props.hydrate) {
|
||||||
|
const comp = defineAsyncComponent(loader)
|
||||||
|
// TODO: fix hydration mismatches on Vue's side. The data-allow-mismatch is ideally a temporary solution due to Vue's SSR limitation with hydrated content.
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
}
|
||||||
|
const strategy: HydrationStrategy = (hydrate) => {
|
||||||
|
props.hydrate!.then(hydrate)
|
||||||
|
return () => {}
|
||||||
|
}
|
||||||
|
const comp = defineAsyncComponent({ loader, hydrate: strategy })
|
||||||
|
return () => h(comp, mergeProps(attrs, { 'data-allow-mismatch': '', 'onVnodeMounted': hydrated }))
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -116,14 +116,15 @@ export const componentsTypeTemplate = {
|
|||||||
c.island || c.mode === 'server' ? `IslandComponent<${type}>` : type,
|
c.island || c.mode === 'server' ? `IslandComponent<${type}>` : type,
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const islandType = 'type IslandComponent<T extends DefineComponent> = T & DefineComponent<{}, {refresh: () => Promise<void>}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, SlotsType<{ fallback: { error: unknown } }>>'
|
const islandType = 'type IslandComponent<T extends DefineComponent> = T & DefineComponent<{}, {refresh: () => Promise<void>}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, SlotsType<{ fallback: { error: unknown } }>>'
|
||||||
|
const delayedType = `type TypeWithDefault<T> = boolean | T\ntype HydrationStrategy = "idle" | "event" | "promise" | "if" | "visible" | "time" | "never"\ntype HydrationMap = { idle: number, event: string | string[], promise: Promise<unknown>, if: boolean | unknown, visible: IntersectionObserverInit, time: number, never: boolean }\ntype DelayedComponent<T extends DefineComponent> = T & DefineComponent<{[K in keyof HydrationMap as \`hydrate:$\{K}\`]?: TypeWithDefault<HydrationMap[K]>},{},{},{},{},{},{hydrated: void},{},{},{},{},{},{},{},{hydrate:{}}>`
|
||||||
return `
|
return `
|
||||||
import type { DefineComponent, SlotsType } from 'vue'
|
import type { DefineComponent, SlotsType } from 'vue'
|
||||||
${nuxt.options.experimental.componentIslands ? islandType : ''}
|
${nuxt.options.experimental.componentIslands ? islandType : ''}
|
||||||
|
${nuxt.options.experimental.delayedHydration ? delayedType : ''}
|
||||||
interface _GlobalComponents {
|
interface _GlobalComponents {
|
||||||
${componentTypes.map(([pascalName, type]) => ` '${pascalName}': ${type}`).join('\n')}
|
${componentTypes.map(([pascalName, type]) => ` '${pascalName}': ${type}`).join('\n')}
|
||||||
${componentTypes.map(([pascalName, type]) => ` 'Lazy${pascalName}': ${type}`).join('\n')}
|
${componentTypes.map(([pascalName, type]) => ` 'Lazy${pascalName}': DelayedComponent<${type}>`).join('\n')}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
@ -131,7 +132,7 @@ declare module 'vue' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
${componentTypes.map(([pascalName, type]) => `export const ${pascalName}: ${type}`).join('\n')}
|
${componentTypes.map(([pascalName, type]) => `export const ${pascalName}: ${type}`).join('\n')}
|
||||||
${componentTypes.map(([pascalName, type]) => `export const Lazy${pascalName}: ${type}`).join('\n')}
|
${componentTypes.map(([pascalName, type]) => `export const Lazy${pascalName}: DelayedComponent<${type}>`).join('\n')}
|
||||||
|
|
||||||
export const componentNames: string[]
|
export const componentNames: string[]
|
||||||
`
|
`
|
||||||
|
@ -219,6 +219,13 @@ export default defineUntypedSchema({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delayed component hydration
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
delayedHydration: false,
|
||||||
|
|
||||||
/** Resolve `~`, `~~`, `@` and `@@` aliases located within layers with respect to their layer source and root directories. */
|
/** Resolve `~`, `~~`, `@` and `@@` aliases located within layers with respect to their layer source and root directories. */
|
||||||
localLayerAliases: true,
|
localLayerAliases: true,
|
||||||
|
|
||||||
|
@ -114,8 +114,8 @@ importers:
|
|||||||
specifier: 3.3.0
|
specifier: 3.3.0
|
||||||
version: 3.3.0
|
version: 3.3.0
|
||||||
eslint-plugin-perfectionist:
|
eslint-plugin-perfectionist:
|
||||||
specifier: 4.0.2
|
specifier: 4.0.3
|
||||||
version: 4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
version: 4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
||||||
eslint-typegen:
|
eslint-typegen:
|
||||||
specifier: 0.3.2
|
specifier: 0.3.2
|
||||||
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
|
version: 0.3.2(eslint@9.15.0(jiti@2.4.0))
|
||||||
@ -4373,8 +4373,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
|
resolution: {integrity: sha512-brcKcxGnISN2CcVhXJ/kEQlNa0MEfGRtwKtWA16SkqXHKitaKIMrfemJKLKX1YqDU5C/5JY3PvZXd5jEW04e0Q==}
|
||||||
engines: {node: '>=5.0.0'}
|
engines: {node: '>=5.0.0'}
|
||||||
|
|
||||||
eslint-plugin-perfectionist@4.0.2:
|
eslint-plugin-perfectionist@4.0.3:
|
||||||
resolution: {integrity: sha512-zWdgyg2SdHqhp/P9d9vKwo5qD9is28xMAGzBslHqkZz5mVIikjyz1qvuJ4yS7Wrsf4KlbGorORefb4Kbe7Puzg==}
|
resolution: {integrity: sha512-CyafnreF6boy4lf1XaF72U8NbkwrfjU/mOf1y6doaDMS9zGXhUU1DSk+ZPf/rVwCf1PL1m+rhHqFs+IcB8kDmA==}
|
||||||
engines: {node: ^18.0.0 || >=20.0.0}
|
engines: {node: ^18.0.0 || >=20.0.0}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
eslint: '>=8.0.0'
|
eslint: '>=8.0.0'
|
||||||
@ -11519,7 +11519,7 @@ snapshots:
|
|||||||
|
|
||||||
eslint-plugin-no-only-tests@3.3.0: {}
|
eslint-plugin-no-only-tests@3.3.0: {}
|
||||||
|
|
||||||
eslint-plugin-perfectionist@4.0.2(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
|
eslint-plugin-perfectionist@4.0.3(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@typescript-eslint/types': 8.15.0
|
'@typescript-eslint/types': 8.15.0
|
||||||
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
'@typescript-eslint/utils': 8.15.0(eslint@9.15.0(jiti@2.4.0))(typescript@5.6.3)
|
||||||
|
@ -2808,6 +2808,80 @@ describe('lazy import components', () => {
|
|||||||
it('lazy load named component with mode server', () => {
|
it('lazy load named component with mode server', () => {
|
||||||
expect(html).toContain('lazy-named-comp-server')
|
expect(html).toContain('lazy-named-comp-server')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('lazy load delayed hydration comps at the right time', async () => {
|
||||||
|
expect(html).toContain('This should be visible at first with network!')
|
||||||
|
const { page } = await renderPage('/lazy-import-components')
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
expect(await page.locator('body').getByText('This shouldn\'t be visible at first with network!').all()).toHaveLength(1)
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with viewport!').all()).toHaveLength(1)
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with events!').all()).toHaveLength(2)
|
||||||
|
// The default value is immediately truthy, however, there is a hydration mismatch without the hack
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with conditions!').all()).toHaveLength(1)
|
||||||
|
const component = page.locator('#lazyevent')
|
||||||
|
const rect = (await component.boundingBox())!
|
||||||
|
await page.mouse.move(rect.x + rect.width / 2, rect.y + rect.height / 2)
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
expect(await page.locator('body').getByText('This shouldn\'t be visible at first with events!').all()).toHaveLength(1)
|
||||||
|
await page.locator('#conditionbutton').click()
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
expect(await page.locator('body').getByText('This shouldn\'t be visible at first with conditions!').all()).toHaveLength(2)
|
||||||
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight))
|
||||||
|
await page.waitForTimeout(300) // Wait for the intersection observer to fire the callback
|
||||||
|
expect(await page.locator('body').getByText('This shouldn\'t be visible at first with viewport!').all()).toHaveLength(2)
|
||||||
|
expect(await page.locator('body').getByText('This should always be visible!').all()).toHaveLength(1)
|
||||||
|
await page.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('respects custom delayed hydration triggers and overrides defaults', async () => {
|
||||||
|
const { page } = await renderPage('/lazy-import-components')
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
const component = page.locator('#lazyevent2')
|
||||||
|
const rect = (await component.boundingBox())!
|
||||||
|
await page.mouse.move(rect.x + rect.width / 2, rect.y + rect.height / 2)
|
||||||
|
await page.waitForTimeout(500)
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with events!').all()).toHaveLength(2)
|
||||||
|
await page.locator('#lazyevent2').click()
|
||||||
|
await page.waitForLoadState('networkidle')
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with events!').all()).toHaveLength(1)
|
||||||
|
expect(await page.locator('body').getByText('This shouldn\'t be visible at first with events!').all()).toHaveLength(1)
|
||||||
|
await page.close()
|
||||||
|
})
|
||||||
|
it('does not delay hydration of components named after modifiers', async () => {
|
||||||
|
const { page } = await renderPage('/lazy-import-components')
|
||||||
|
expect(await page.locator('body').getByText('This fake lazy event should be visible!').all()).toHaveLength(1)
|
||||||
|
expect(await page.locator('body').getByText('This fake lazy event shouldn\'t be visible!').all()).toHaveLength(0)
|
||||||
|
})
|
||||||
|
it('handles time-based hydration correctly', async () => {
|
||||||
|
const { page } = await renderPage('/lazy-import-components/time')
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with time!').all()).toHaveLength(2)
|
||||||
|
await page.waitForTimeout(500)
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with time!').all()).toHaveLength(1)
|
||||||
|
await page.waitForTimeout(1600) // Some room for falkiness and intermittent lag
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with time!').all()).toHaveLength(0)
|
||||||
|
})
|
||||||
|
it('handles promise-based hydration correctly', async () => {
|
||||||
|
const { page } = await renderPage('/lazy-import-components/promise')
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with promise!').all()).toHaveLength(1)
|
||||||
|
await page.waitForTimeout(2100) // Some room for falkiness and intermittent lag
|
||||||
|
expect(await page.locator('body').getByText('This should be visible at first with promise!').all()).toHaveLength(0)
|
||||||
|
})
|
||||||
|
it('keeps reactivity with models', async () => {
|
||||||
|
const { page } = await renderPage('/lazy-import-components/model-event')
|
||||||
|
expect(await page.locator('#count').textContent()).toBe('0')
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
expect(await page.locator('#count').textContent()).toBe(`${i}`)
|
||||||
|
await page.locator('#inc').click()
|
||||||
|
}
|
||||||
|
expect(await page.locator('#count').textContent()).toBe('10')
|
||||||
|
})
|
||||||
|
it('emits hydration events', async () => {
|
||||||
|
const { page, consoleLogs } = await renderPage('/lazy-import-components/model-event')
|
||||||
|
expect(consoleLogs.some(log => log.type === 'log' && log.text === 'Component hydrated')).toBeFalsy()
|
||||||
|
await page.locator('#count').click()
|
||||||
|
expect(consoleLogs.some(log => log.type === 'log' && log.text === 'Component hydrated')).toBeTruthy()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('defineNuxtComponent watch duplicate', () => {
|
describe('defineNuxtComponent watch duplicate', () => {
|
||||||
|
5
test/fixtures/basic/components/DelayedCondition.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedCondition.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This shouldn't be visible at first with conditions!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedCondition.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedCondition.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should be visible at first with conditions!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedEvent.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedEvent.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This shouldn't be visible at first with events!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedEvent.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedEvent.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should be visible at first with events!
|
||||||
|
</div>
|
||||||
|
</template>
|
15
test/fixtures/basic/components/DelayedModel.vue
vendored
Normal file
15
test/fixtures/basic/components/DelayedModel.vue
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<span id="count">{{ model }}</span>
|
||||||
|
<button
|
||||||
|
id="inc"
|
||||||
|
@click="model++"
|
||||||
|
>
|
||||||
|
Increment
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const model = defineModel()
|
||||||
|
</script>
|
5
test/fixtures/basic/components/DelayedNetwork.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedNetwork.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This shouldn't be visible at first with network!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedNetwork.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedNetwork.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should be visible at first with network!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedNever.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedNever.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should never be visible!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedNever.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedNever.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should always be visible!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedPromise.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedPromise.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This shouldn't be visible at first with promise!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedPromise.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedPromise.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should be visible at first with promise!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedTime.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedTime.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This shouldn't be visible at first with time!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedTime.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedTime.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should be visible at first with time!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedVisible.client.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedVisible.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This shouldn't be visible at first with viewport!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/DelayedVisible.server.vue
vendored
Normal file
5
test/fixtures/basic/components/DelayedVisible.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This should be visible at first with viewport!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/EventView.client.vue
vendored
Normal file
5
test/fixtures/basic/components/EventView.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This fake lazy event should be visible!
|
||||||
|
</div>
|
||||||
|
</template>
|
5
test/fixtures/basic/components/EventView.server.vue
vendored
Normal file
5
test/fixtures/basic/components/EventView.server.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
This fake lazy event shouldn't be visible!
|
||||||
|
</div>
|
||||||
|
</template>
|
1
test/fixtures/basic/nuxt.config.ts
vendored
1
test/fixtures/basic/nuxt.config.ts
vendored
@ -172,6 +172,7 @@ export default defineNuxtConfig({
|
|||||||
renderJsonPayloads: process.env.TEST_PAYLOAD !== 'js',
|
renderJsonPayloads: process.env.TEST_PAYLOAD !== 'js',
|
||||||
headNext: true,
|
headNext: true,
|
||||||
inlineRouteRules: true,
|
inlineRouteRules: true,
|
||||||
|
delayedHydration: true,
|
||||||
},
|
},
|
||||||
compatibilityDate: '2024-06-28',
|
compatibilityDate: '2024-06-28',
|
||||||
nitro: {
|
nitro: {
|
||||||
|
@ -3,5 +3,37 @@
|
|||||||
<LazyNCompAll message="lazy-named-comp-all" />
|
<LazyNCompAll message="lazy-named-comp-all" />
|
||||||
<LazyNCompClient message="lazy-named-comp-client" />
|
<LazyNCompClient message="lazy-named-comp-client" />
|
||||||
<LazyNCompServer message="lazy-named-comp-server" />
|
<LazyNCompServer message="lazy-named-comp-server" />
|
||||||
|
<LazyDelayedEvent
|
||||||
|
id="lazyevent"
|
||||||
|
hydrate:event
|
||||||
|
/>
|
||||||
|
<LazyEventView />
|
||||||
|
<LazyDelayedVisible hydrate:visible />
|
||||||
|
<LazyDelayedNever hydrate:never />
|
||||||
|
<LazyDelayedEvent
|
||||||
|
id="lazyevent2"
|
||||||
|
:hydrate:event="['click']"
|
||||||
|
/>
|
||||||
|
<LazyDelayedCondition
|
||||||
|
id="lazycondition"
|
||||||
|
hydrate:if
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
id="conditionbutton"
|
||||||
|
@click="state++"
|
||||||
|
/>
|
||||||
|
<LazyDelayedCondition
|
||||||
|
id="lazycondition2"
|
||||||
|
:hydrate:if="state > 1"
|
||||||
|
/>
|
||||||
|
<LazyDelayedNetwork hydrate:idle />
|
||||||
|
<div style="height:3000px">
|
||||||
|
This is a very tall div
|
||||||
|
</div>
|
||||||
|
<LazyDelayedVisible hydrate:visible />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const state = useState('delayedHydrationCondition', () => 1)
|
||||||
|
</script>
|
||||||
|
16
test/fixtures/basic/pages/lazy-import-components/model-event.vue
vendored
Normal file
16
test/fixtures/basic/pages/lazy-import-components/model-event.vue
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyDelayedModel
|
||||||
|
v-model="model"
|
||||||
|
hydrate:event
|
||||||
|
@hydrated="log"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const model = ref(0)
|
||||||
|
function log () {
|
||||||
|
console.log('Component hydrated')
|
||||||
|
}
|
||||||
|
</script>
|
15
test/fixtures/basic/pages/lazy-import-components/promise.vue
vendored
Normal file
15
test/fixtures/basic/pages/lazy-import-components/promise.vue
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const pr = new Promise((resolve) => { setTimeout(resolve, 500) })
|
||||||
|
const prImmediate = Promise.resolve(42)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyDelayedPromise
|
||||||
|
:hydrate:promise="pr"
|
||||||
|
/>
|
||||||
|
<LazyDelayedPromise
|
||||||
|
:hydrate:promise="prImmediate"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
8
test/fixtures/basic/pages/lazy-import-components/time.vue
vendored
Normal file
8
test/fixtures/basic/pages/lazy-import-components/time.vue
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<LazyDelayedTime hydrate:time />
|
||||||
|
<LazyDelayedTime
|
||||||
|
:hydrate:time="500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user