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

It's impossible to set both x & y in useScroll synchronously #3809

Closed
7 tasks done

Comments

@pieczorx
Copy link

Describe the bug

when you import useScroll

import {useScroll} from '@vueuse/core'

const {x, y} = useScroll(el)

and define these functions

function a() {
  x.value = 123
}

function b() {
  y.value = 123
}

function c() {
  x.value = 123
  y.value = 123
}

few things will happen:

  1. a() will work perfectly
  2. b() will work perfectly
  3. c() will cause only y to update and leave x with previous value

It's probably related to reactivity in Vue but it's actually possible to do 2 things on vueUse side:
a) don't rely on reactivity while doing scrollTo inside this module
b) expose scrollTo method to developers

See the repro for more information 😄

Reproduction

https://stackblitz.com/edit/vitejs-vite-helfwa?file=src%2FApp.vue

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Memory: 9.72 GB / 31.68 GB
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.0.2 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.112)
    Internet Explorer: 11.0.22621.1


+ @vueuse/core": "^10.7.2",

Used Package Manager

yarn

Validations

@antfu antfu closed this as completed in 317cab6 May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment