mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-03 13:24:04 +00:00
[autofix.ci] apply automated fixes
This commit is contained in:
parent
0ab38fcd09
commit
cf9a905993
@ -38,6 +38,6 @@ export const createVisibleLoader = (opts: Partial<IntersectionObserverInit>) =>
|
||||
|
||||
/**
|
||||
* A utility used to determine which events should trigger hydration in components with event-based delayed hydration.
|
||||
* @param events an array of events that will be used to trigger the hydration
|
||||
* @param events an array of events that will be used to trigger the hydration
|
||||
*/
|
||||
export const createEventLoader = (events: Array<keyof HTMLElementEventMap>) => events
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createStaticVNode, createVNode, defineComponent, getCurrentInstance, h, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import type { Component, Ref, ComponentInternalInstance } from 'vue'
|
||||
import type { Component, ComponentInternalInstance, Ref } from 'vue'
|
||||
// import ClientOnly from '#app/components/client-only'
|
||||
import { getFragmentHTML } from '#app/components/utils'
|
||||
import { useNuxtApp } from '#app/nuxt'
|
||||
@ -90,7 +90,7 @@ export const createLazyNetworkClientPage = (componentLoader: Component) => {
|
||||
})
|
||||
}
|
||||
|
||||
const eventsMapper = new WeakMap<ComponentInternalInstance,(() => void)[]>()
|
||||
const eventsMapper = new WeakMap<ComponentInternalInstance, (() => void)[]>()
|
||||
/* @__NO_SIDE_EFFECTS__ */
|
||||
export const createLazyEventClientPage = (componentLoader: Component) => {
|
||||
return defineComponent({
|
||||
@ -109,7 +109,7 @@ export const createLazyEventClientPage = (componentLoader: Component) => {
|
||||
events.forEach((event) => {
|
||||
const handler = () => {
|
||||
isTriggered.value = true
|
||||
registeredEvents.forEach((remove) => remove())
|
||||
registeredEvents.forEach(remove => remove())
|
||||
eventsMapper.delete(instance)
|
||||
}
|
||||
instance.vnode.el?.addEventListener(event, handler)
|
||||
@ -118,10 +118,10 @@ export const createLazyEventClientPage = (componentLoader: Component) => {
|
||||
eventsMapper.set(instance, registeredEvents)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
registeredEvents?.forEach((remove) => remove())
|
||||
registeredEvents?.forEach(remove => remove())
|
||||
eventsMapper.delete(instance)
|
||||
})
|
||||
return () => isTriggered.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createVNode(createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1)) : null
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -2676,7 +2676,7 @@ describe('lazy import components', () => {
|
||||
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(1)
|
||||
const component = await page.locator('#lazyevent');
|
||||
const component = await 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')
|
||||
|
@ -2,4 +2,4 @@
|
||||
<div>
|
||||
This shouldn't be visible at first with events!
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
@ -2,4 +2,4 @@
|
||||
<div>
|
||||
This should be visible at first with events!
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<LazyNCompAll message="lazy-named-comp-all" />
|
||||
<LazyNCompClient message="lazy-named-comp-client" />
|
||||
<LazyNCompServer message="lazy-named-comp-server" />
|
||||
<LazyEventDelayedEvent id="lazyevent"/>
|
||||
<LazyEventDelayedEvent id="lazyevent" />
|
||||
<LazyIdleDelayedNetwork />
|
||||
<div style="height:3000px">
|
||||
This is a very tall div
|
||||
|
Loading…
Reference in New Issue
Block a user