https://github.com/catamphetamine/request-animation-frame-timeout
`request-animation-frame-timeout`
https://github.com/catamphetamine/request-animation-frame-timeout
Last synced: 3 months ago
JSON representation
`request-animation-frame-timeout`
- Host: GitHub
- URL: https://github.com/catamphetamine/request-animation-frame-timeout
- Owner: catamphetamine
- Created: 2024-06-03T23:51:36.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-04T22:11:00.000Z (about 1 year ago)
- Last Synced: 2025-01-11T01:48:46.591Z (5 months ago)
- Language: JavaScript
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `request-animation-frame-timeout`
## Rationale
For some weird reason, in Chrome, `setTimeout()` would lag up to a second (or more) behind. Turns out, Chrome developers have deprecated `setTimeout()` API entirely without asking anyone. Replacing `setTimeout()` with `requestAnimationFrame()` can work around that Chrome bug. The timer-freezing behavior of Chrome is inherently retarded, so this workaround wouldn't be required if they designed their corporate web browser properly.
* [Fix Chrome setTimeout throttling](https://github.com/bvaughn/react-virtualized/issues/722)
* [Issue 570845: setInterval and setTimeout stop during input when timer callbacks are expensive](https://bugs.chromium.org/p/chromium/issues/detail?id=570845)## Use
```
npm install request-animation-frame-timeout --save
``````js
import { setTimeout, clearTimeout } from 'request-animation-frame-timeout'
```## Warning
`requestAnimationFrame()` doesn't get called when a web browser tab is not visible (minimized or in background). When a web page goes non-visible, all `requestAnimationFrame()` timers will be paused until the page is visible again. For this reason, `requestAnimationFrame()` timers should only be used for user-interface-related stuff (visual transitions, user input timers, etc).