Skip to content

Commit

Permalink
fix: onScopeDispose guard
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 21, 2024
1 parent 8bcfcad commit 0ed15fe
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Ref,
ShallowRef,
computed,
getCurrentScope,
onScopeDispose,
ref,
toValue,
Expand Down Expand Up @@ -36,9 +37,11 @@ export function useEventListener(
options?: boolean | AddEventListenerOptions
) {
target.addEventListener(event, listener, options)
onScopeDispose(() => {
target.removeEventListener(event, listener)
})
if (getCurrentScope()) {
onScopeDispose(() => {
target.removeEventListener(event, listener)
})
}
}

export const IS_CLIENT = typeof window !== 'undefined'
Expand Down

0 comments on commit 0ed15fe

Please sign in to comment.