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(scroll): scroll direction inconsistency #1629

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

victorcg88
Copy link
Contributor

Pull request template

After the Vue3 upgrade the useScroll composable created a inconsistency in the scroll direction prop in the useScroll instance and the scroll direction prop in the Vuex store.

Explanation:

When scrolling, the data in useScroll is updated via the storeScrollData method, which updates values on currentPosition and clientHeight. For the first scroll event, the behavior is described below:

In Vue2 the running order was:

  1. Callback of clientHeight watch, which blocks updates on scroll direction because isClientHeightChanging is set to true.
  2. Callback of currentPosition watch, skipped due to isClientHeightChanging = true.

But in Vue3 the running order is:

  1. Callback of currentPosition watch, because in the running order of storeScrollData currentPosition is mutated first. Then isClientHeightChanging is false, so it mutates scrollDirection
  2. Callback of clientHeight watch, which blocks updates on scroll direction because isClientHeightChanging is set to true.
  3. Callback of scrollDirection watch, skipped due to isClientHeightChanging = true. So the event is not emitted and the store keeps the original value not the current one.

Consequences:

In the x-archetype, it is used the useHasScrollPastThreshold composable which relies on the scroll direction of the store. It is used in this case to collapse the subheader of the desktop and mobile layouts. Those subheaders were not hidden due to this bug.

How it is fixed:

Changing the running order of the storeScrollData mutating first the clientHeight, it is ensured that the data is consistent between the composable and the store.

Before:

Screen.Recording.2024-10-01.at.17.43.42.mov

After:

Screen.Recording.2024-10-01.at.17.41.49.mov

Motivation and context

  • Dependencies. If any, specify:
  • Open issue. If applicable, link:

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that causes existing functionality to not work as expected)
  • Change requires a documentation update

What is the destination branch of this PR?

How has this been tested?

Tests performed according to testing guidelines:

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review on my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

@joseacabaneros joseacabaneros merged commit ad970ae into vue3-update-rc Oct 3, 2024
2 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.

2 participants