Skip to content

BUG | useThrottleFn | leading false option doesn't work properly #4920

@MansurAliKoroglu

Description

@MansurAliKoroglu

Describe the bug

Recently I compared lodash's throttle and useThrottleFn. I found the leading and trailing options are different between them.

  • Here is how both differs when we call the throttled function 3 times, without waiting, as call1, call2 and call3
Leading Trailing Lodash throttle Vueuse useThrottleFn
True True call1 runs immediately. call3 runs after timeout call1 runs immediately. call3 runs after timeout
True False only call1 runs immediately only call1 runs immediately
False True only call3 runs after the timeout call2 runs immediately, call3 runs after timeout
False False nothing runs only call2 runs immediately

So if this isn't intended behavior, that shows there is a problem with leading false option. When leading is false, the second call of the throttled function immediately triggers it.

If you confirm this isn't intended behavior and a bug, I can create a PR with confirming test cases for it too.

This also might be related with #4551

Reproduction

https://stackblitz.com/edit/vueuse-lodash-throttle-compare?file=README.md

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vueuse/core: ^13.5.0 => 13.5.0

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions