8000 fix(useScroll): use mutationObserver to update arrivedState when the DOM is changed by andylou0102 · Pull Request #4433 · vueuse/vueuse · GitHub
[go: up one dir, main page]

Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

andylou0102
Copy link
@andylou0102 andylou0102 commented Dec 26, 2024

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

close #4265

Additional context

My test below ( forked from haykkh )

https://stackblitz.com/edit/vitejs-vite-vthxo9?file=src%2FuseScrollTest.js

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 26, 2024
@OrbisK
Copy link
Collaborator
OrbisK commented Jan 22, 2025

@andylou0102 Would it be possible for you to add tests (vitest), to prevent regression.

@andylou0102
Copy link
Author

Sure, I'll add tests using Vitest to ensure no regressions.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 1, 2025
@andylou0102
Copy link
Author

@OrbisK I've added the tests to cover boundary detection and DOM mutation cases.

@andylou0102
Copy link
Author

@OrbisK Sorry, I missed the element type check earlier, but I think it should be fine now.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 13, 2025
ilyaliao
ilyaliao previously approved these changes Mar 13, 2025
* such as attribute modifications, child node additions or removals, or subtree changes.
* @default false
*/
observe?: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding #4655

lets maybe do

Suggested change
observe?: boolean
observe?: boolean | {mutation: boolean}

so we can have {mutation: boolean, resize: boolean} with #4655

Like this we can merge this PR and update #4655 to support this :)

Copy link
Collaborator

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 😃

Copy link
Author
@andylou0102 andylou0102 Apr 1, 2025

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.

Copy link
Author

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

@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Mar 21, 2025
@andylou0102 andylou0102 force-pushed the fix/add-mutation-observer-in-useScroll branch from 08c14f8 to 32d00e9 Compare April 1, 2025 16:51
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer needs test size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

useScroll's arrivedState not responsive to changes in DOM
3 participants
0