-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(useElementVisibility): Resolve possible issue with once watcher inside of callback #4723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
So this is more of a structural optimization, right? |
Yeah, it was a structural optimization. |
It looks good to me, but I'm not sure if this addresses the requirements described in #4704. |
Thanks for the review! |
vi.mock('../watchOnce', () => { | ||
return { | ||
watchOnce: vi.fn((source, callback) => { | ||
// Immediately execute the callback if the source is true | ||
if (typeof source === 'object' && source.value === true) { | ||
callback(true) | ||
} | ||
}), | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to mock this? 🤔
Before submitting the PR, please make sure you do the following
fixes #123
).Description
fix #4704
Problem solved: The watchOnce call in useElementVisibility is happening inside of the intersection callback.
Solution: I moved the watchOnce call outside of the intersection callback to ensure it is only registered once when the composable is initialized.
Additional context