Description
Describe the bug
useNow
has the option to provide an interval to use for refreshing the 'now' Date. Currently, the default interval is set to requestAnimationFrame
, which, if I'm not mistaken, updates the value 60 times per second for a 60hz display (or 144x for 144hz, etc.).
While I'm sure it has its use cases to update the value this often, I feel like it is overkill for the majority of situations. In my project, I've noticed that using the "bare" value produced by this composition utility uses 5%(ish) of my CPU's capacity. Doing any sort of transformation on the data, such as passing it through some i18n magic as is the case with my project, causes the browser to freeze because 100% of the CPU is occupied with updating this one ref.
As such, I propose to set the default interval to 1000 ms, which still leaves the option to increase or decrease it as the user's request, or to use requestAnimationFrame
if so desired.
To make life easier if people agree with me, I'll provide a PR that fixes this issue.
Reproduction
System Info
System:
OS: Linux 5.15 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
CPU: (14) x64 Intel(R) Core(TM) Ultra 7 155U
Memory: 8.21 GB / 15.35 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm
pnpm: 9.15.5 - ~/.nvm/versions/node/v20.18.0/bin/pnpm
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.