diff --git a/packages/ui/src/composables/std/event/useEvent.ts b/packages/ui/src/composables/std/event/useEvent.ts index 0695f19644..67ddab2446 100644 --- a/packages/ui/src/composables/std/event/useEvent.ts +++ b/packages/ui/src/composables/std/event/useEvent.ts @@ -26,17 +26,24 @@ export const useEvent = ( listener: (this: GlobalEventHandlers, event: UseEventEvent) => any, target?: MaybeRef | boolean, ) => { + const window = useWindow() + const source = (target && typeof target !== 'boolean') ? computed(() => { const t = unref(target) + if (typeof Window === 'undefined') { + // No need to listen on server + return null + } + if (t instanceof Window) { return t } return unwrapEl(t) }) - : useWindow() + : window const capture = typeof target === 'boolean' ? target : false watch(source, (newValue, oldValue) => {