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

requestIdleCallback: callback's IdleDeadline API is not implemented #358

Open
dvoytenko opened this issue Jan 19, 2021 · 4 comments
Open

Comments

@dvoytenko
Copy link

We understand you have a problem and are in a hurry, but please provide us with some info to make it much more likely for your issue to be understood, worked on and resolved quickly.

  • FakeTimers version : appears to still exist at HEAD
  • Environment : any
  • Other libraries you are using: sinon

What did you expect to happen?

install() by default patches requestIdleCallback. But when the callback is called, it doesn't have IdleDeadline argument. It's described here. Thus a code that may use this argument will fail.

How to reproduce

Describe with code how to reproduce the faulty behaviour
or link to code on JSBin or similar

A sample code is:

requestIdleCallback(function(deadline) {
  if (deadline.timeRemaining() > 0) {
    ...
  }
})
@fatso83
Copy link
Contributor

fatso83 commented Jan 20, 2021

Thanks for noting this!

P.S. Quickest way of getting your itch scratch is scratching it yourselves. PRs welcome ;)

@fatso83
Copy link
Contributor

fatso83 commented May 28, 2021

Hi, I looked into this, and found several issues.

  1. Your issue - the callback not getting the argument.
  2. The actual current implementation is wrong. It uses a number for the timeout, instad of { timeout } (an object).
  3. It does nothing with the timeout. It should schedule the timer to be called at timeout if it has not been called.

All of these are quite simple, but the third requires some effort and tests. would love a hand ... :)

@fatso83
Copy link
Contributor

fatso83 commented Nov 22, 2022

This is actually mostly done in #421, but requires some debugging to fix the broken tests

Copy link

stale bot commented Dec 27, 2023

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 stale bot added the stale label Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants