Skip to content

Comments

feat: support configurable schedulers for timed composables#5070

Closed
9romise wants to merge 15 commits intomainfrom
fest/scheduler
Closed

feat: support configurable schedulers for timed composables#5070
9romise wants to merge 15 commits intomainfrom
fest/scheduler

Conversation

@9romise
Copy link
Member

@9romise 9romise commented Sep 25, 2025

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

This PR unifies the options of composables built on top of useIntervalFn and introduces a customizable scheduler option:

There are also a few functions that currently allow choosing between useRafFn and useIntervalFn through an interval option. I didn’t make changes to those in this PR, and I’d like to hear everyone’s thoughts on this. If we can make the custom scheduler compatible with both useIntervalFn and useRafFn, it will avoid having to import both useIntervalFn and useRafFn.

We can update the configurations documentation once we’ve discussed and agreed on a suitable approach.

Additional context

Related: #5043

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 25, 2025

Open in StackBlitz

@vueuse/components

npm i https://pkg.pr.new/@vueuse/components@5070

@vueuse/core

npm i https://pkg.pr.new/@vueuse/core@5070

@vueuse/electron

npm i https://pkg.pr.new/@vueuse/electron@5070

@vueuse/firebase

npm i https://pkg.pr.new/@vueuse/firebase@5070

@vueuse/integrations

npm i https://pkg.pr.new/@vueuse/integrations@5070

@vueuse/math

npm i https://pkg.pr.new/@vueuse/math@5070

@vueuse/metadata

npm i https://pkg.pr.new/@vueuse/metadata@5070

@vueuse/nuxt

npm i https://pkg.pr.new/@vueuse/nuxt@5070

@vueuse/router

npm i https://pkg.pr.new/@vueuse/router@5070

@vueuse/rxjs

npm i https://pkg.pr.new/@vueuse/rxjs@5070

@vueuse/shared

npm i https://pkg.pr.new/@vueuse/shared@5070

commit: 618461b

@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 61.76471% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.72%. Comparing base (68807a7) to head (618461b).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
packages/core/useMemory/index.ts 0.00% 16 Missing ⚠️
packages/core/useElementByPoint/index.ts 11.11% 8 Missing ⚠️
packages/shared/useInterval/index.ts 0.00% 8 Missing ⚠️
packages/core/useVibrate/index.ts 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5070      +/-   ##
==========================================
+ Coverage   65.93%   66.72%   +0.78%     
==========================================
  Files         365      365              
  Lines       14565    14624      +59     
  Branches     2388     2409      +21     
==========================================
+ Hits         9604     9758     +154     
+ Misses       4950     4855      -95     
  Partials       11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antfu
Copy link
Member

antfu commented Oct 1, 2025

I would be happy to see useRafFn to be a valid scheduler

@9romise 9romise changed the title feat: add custom scheduler option to useIntervalFn-based composables and unify options feat: support configurable schedulers for timed composables Oct 1, 2025
/**
* Custom scheduler to use for interval execution.
*
* @default useRafFn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference is the default value in the JSDoc; I'm not sure if there's a better way to make it more noticeable to users.

/**
* Start the interval immediately
*
* @default false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

}, options?.interval ?? 1000, { immediate: options?.immediate ?? false })
const {
scheduler = useIntervalFn,
interval = 1000,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to get some opinions on whether it’s necessary to explicitly set default values in the top-level functions, rather than passing undefined and letting the underlying scheduler handle it.

Just want to note that different functions handle this differently, and all properties in SchedulerOptions have this situation.

@9romise 9romise marked this pull request as ready for review October 1, 2025 16:33
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Oct 1, 2025
@9romise
Copy link
Member Author

9romise commented Oct 1, 2025

I would be happy to see useRafFn to be a valid scheduler

Absolutely agree! I did run into some issues earlier, but after some more thought, I realized I was overcomplicating it. I've now found a clean solution and have pushed the updates.

*/
export function useIntervalFn(cb: Fn, interval: MaybeRefOrGetter<number> = 1000, options: UseIntervalFnOptions = {}): UseIntervalFnReturn {
export function useIntervalFn(cb: Fn, interval: MaybeRefOrGetter<number>, options?: UseIntervalFnOptions): UseIntervalFnReturn
export function useIntervalFn(cb: Fn, options?: SchedulerOptions): UseIntervalFnReturn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overloaded the method and implemented the Scheduler interface.

@9romise
Copy link
Member Author

9romise commented Oct 1, 2025

Since this PR touches multiple files, I'd recommend adding tests to prevent regressions before we merge.

@9romise
Copy link
Member Author

9romise commented Oct 1, 2025

I'd like to gather some input on:

  1. Whether we should unify the default values for each method
  2. Whether we should explicitly set default values for each method at the top level
  3. Whether there’s a better way to handle different default values across methods without breaking the user experience

@9romise 9romise marked this pull request as draft October 2, 2025 13:06
@9romise 9romise closed this Nov 11, 2025
@9romise 9romise deleted the fest/scheduler branch November 11, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants