Skip to content

Commit

Permalink
fix(composables/std): Window is not defined on server
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ksem committed Nov 15, 2024
1 parent fe21794 commit 0d56c5f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/ui/src/composables/std/event/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@ export const useEvent = <N extends UseEventEventName, E extends Event>(
listener: (this: GlobalEventHandlers, event: UseEventEvent<N, E>) => any,
target?: MaybeRef<TemplateRef | Window> | 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) => {
Expand Down

0 comments on commit 0d56c5f

Please sign in to comment.