Skip to content
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

fix(useInfiniteScroll): re-measure arrived states when async infinite scroll resolves #3030

Merged
merged 5 commits into from May 1, 2023

Conversation

scottbedard
Copy link
Member

@scottbedard scottbedard commented Apr 26, 2023

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

Issue: #3019

Our useInfiniteScroll composable is not working with async functions. This is caused by arrivedState[direction] never being set to false when the container is resized.

This state becomes stuck because the measurement of these values only happens during onScrollHandler, and so if the user is no longer scrolling, no re-measurement occurs and we enter the infinite loop.

The simplest way to force a measurement is just to fire a scroll event ourselves, but this may not be the fix we want. We might want to let useScroll handle observation of it's height, but this would require a larger refactor. Let me know if that's the route we'd rather go and I'll make the changes.

Another solution that might be a happy medium is for useScroll to return a function that can force a re-measurement. This might be the most flexible solution, because it would allow for measurements to happen for whatever reason we want 🤔

Update: I've made the refactor to return a force-measurement function, I think I like this better, but let me know what you think! If we'd rather force the measurement by just firing a scroll event, we can revert 87d6757

Additional context


🤖 Generated by Copilot at e44a129

Fix initial load bug in useInfiniteScroll hook. Dispatch scroll event on observed element to trigger fetch function.

🤖 Generated by Copilot at e44a129

  • Dispatch scroll event on observed element to trigger initial data load (link)

@scottbedard scottbedard changed the title WIP: fix async infinite scrolling fix(useInfiniteScroll): re-measure arrived states when async infinite scroll resolves Apr 26, 2023
@@ -74,6 +74,7 @@ export function useInfiniteScroll(
])
.finally(() => {
promise.value = null
state.measure()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could put this at the beginning of checkAndLoad? Here I think it's better to do after nextTick

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, I like that better! Resolved 0ef4e25

@scottbedard scottbedard requested a review from antfu April 27, 2023 16:02
@antfu antfu merged commit a88fea2 into vueuse:main May 1, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants