-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(useScroll): use mutationObserver to update arrivedState when the DOM is changed #4433
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?
fix(useScroll): use mutationObserver to update arrivedState when the DOM is changed #4433
Conversation
@andylou0102 Would it be possible for you to add tests (vitest), to prevent regression. |
Sure, I'll add tests using Vitest to ensure no regressions. |
@OrbisK I've added the tests to cover boundary detection and DOM mutation cases. |
@OrbisK Sorry, I missed the element type check earlier, but I think it should be fine now. |
packages/core/useScroll/index.ts
Outdated
* such as attribute modifications, child node additions or removals, or subtree changes. | ||
* @default false | ||
*/ | ||
observe?: boolean |
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.
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.
@andylou0102 I think if we add this, we can merge this soon 😃
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.
Ok, the observe option has been updated to boolean | { mutation: boolean }
to support more specific observation settings and provide extensibility for #4655 in future.
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.
@OrbisK I wrote a piece of logic to construct observe, aiming to allow users to control it in a simple way (without worrying about whether it's mutation
or resize
), while internally unifying it into an object for distinction.
In my opinion, after adding resize
, it would look like this :
const observe = typeof _observe === 'boolean'
? {
mutation: _observe,
resize: _observe
}
: _observe;
Passing a boolean will toggle both mutation
and resize
at the same time. If the user needs fine-grained control, they can pass an object to configure it manually.
commit
08c14f8
to
32d00e9
Compare
Before submitting the PR, please make sure you do the following
fixes #123
).Description
close #4265
Additional context
My test below ( forked from haykkh )
https://stackblitz.com/edit/vitejs-vite-vthxo9?file=src%2FuseScrollTest.js