vueuse/vueuse

BUG | `useElementVisibility` | Possible issue with `once` watcher inside of callback

Open

#4,704 opened on Apr 13, 2025

View on GitHub
 (1 comment) (1 reaction) (0 assignees)TypeScript (2,269 forks)batch import
good first issuehas pr

Repository metrics

Stars
 (18,007 stars)
PR merge metrics
 (Avg merge 34d 8h) (18 merged PRs in 30d)

Description

Describe the bug

I was looking at the source code for this composable and noticed that the watchOnce call is happening inside of the intersection callback.

https://github.com/vueuse/vueuse/blob/44b402ef2c236c6418fab9526443db0ba9f8b8b4/packages/core/useElementVisibility/index.ts#L60-L64

Was this intentional? Wouldn't this create a new watcher on each update, kind of separate to the initial effect scope? I would have guessed that this hook would have to be outside of the useIntersectionObserver call.

Reproduction

n/a

System Info

n/a

Used Package Manager

npm

Validations

Contributor guide