diff --git a/packages/nuxt/src/components/runtime/client-delayed-component.ts b/packages/nuxt/src/components/runtime/client-delayed-component.ts index 9c1d29facd..8f00b99061 100644 --- a/packages/nuxt/src/components/runtime/client-delayed-component.ts +++ b/packages/nuxt/src/components/runtime/client-delayed-component.ts @@ -102,7 +102,7 @@ export const createLazyEventClientPage = (componentLoader: Component) => { const nuxt = useNuxtApp() const instance = getCurrentInstance()! const isTriggered = ref(false) - const events: string[] = attrs.loader ?? ['mouseover'] + const events: string[] = attrs.loader as string[] ?? ['mouseover'] const registeredEvents: (() => void)[] = [] onMounted(() => { @@ -112,8 +112,8 @@ export const createLazyEventClientPage = (componentLoader: Component) => { registeredEvents.forEach((remove) => remove()) eventsMapper.delete(instance) } - instance.vnode.el.addEventListener(event, handler) - registeredEvents.push(() => instance.vnode.el.removeEventListener(event, handler)) + instance.vnode.el?.addEventListener(event, handler) + registeredEvents.push(() => instance.vnode.el?.removeEventListener(event, handler)) }) eventsMapper.set(instance, registeredEvents) }) @@ -124,4 +124,4 @@ export const createLazyEventClientPage = (componentLoader: Component) => { return () => isTriggered.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createVNode(createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1)) : null } }) -} \ No newline at end of file +}