vueuse icon indicating copy to clipboard operation
vueuse copied to clipboard

watchDebounced return incorrect oldValue

Open asvishnyakov opened this issue 2 years ago • 6 comments

Describe the bug

There is difference in how will work refDebounced + watch and watchDebounced.

Let's say we have a series of value changes:

  • initial value is 1
  • then value is changed to 2
  • then to 3.
  1. If you will use refDebounced + watch, oldValue is the value of reference before modifications, i.e. 1 (which is expected)
  2. If you will use watchDebounced, oldValue is the value of last modifiction, i.e. 2 (which is unexpected).

That's because watchDebounced simply filter all events until the last one before time expire.

Reproduction

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

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz
    Memory: 3.79 GB / 15.91 GB
  Binaries:
    Node: 18.15.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 3.6.1 - E:\storefront\vc-theme-b2b-vue\node_modules\.bin\yarn.CMD
    npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.2283.0), Chromium (117.0.2045.31)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vueuse/components: ^10.1.2 => 10.4.1
    @vueuse/core: ^10.1.2 => 10.4.1
    @vueuse/head: ~0.9.8 => 0.9.8
    vue: ^3.3.4 => 3.3.4

Used Package Manager

yarn

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guidelines.
  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
  • [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion.
  • [X] The provided reproduction is a minimal reproducible example of the bug.

asvishnyakov avatar Sep 18 '23 13:09 asvishnyakov

Hey guys, any news on that?

asvishnyakov avatar Nov 03 '23 04:11 asvishnyakov

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 02 '24 07:01 stale[bot]

Adding here that not only the problem is still there, but the workaround (refDebounced + watch) does not work for reactive objects.

rafaellehmkuhl avatar Aug 10 '24 23:08 rafaellehmkuhl

@rafaellehmkuhl Please create separate issue with mention of this one to catch attention of the team. I don't believe they review closed issues

asvishnyakov avatar Aug 20 '24 18:08 asvishnyakov

I have the same bug. @antfu can you re-open?

mesqueeb avatar Sep 24 '25 03:09 mesqueeb

Can you share an up to date reproduction @mesqueeb?

OrbisK avatar Sep 24 '25 08:09 OrbisK