Skip to content

Commit

Permalink
fix(common): use setTimeout as fallback for requestIdleCallback (#…
Browse files Browse the repository at this point in the history
…2406)

Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
artwooood and holic authored Mar 11, 2024
1 parent a3d8966 commit 8269307
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cold-books-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/common": patch
---

`waitForIdle` now falls back to `setTimeout` for environments without `requestIdleCallback`.
6 changes: 5 additions & 1 deletion packages/common/src/utils/waitForIdle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export function waitForIdle(): Promise<void> {
return new Promise<void>((resolve) => {
requestIdleCallback(() => resolve());
if (typeof requestIdleCallback !== "undefined") {
requestIdleCallback(() => resolve());
} else {
setTimeout(() => resolve(), 1);
}
});
}

0 comments on commit 8269307

Please sign in to comment.