Skip to content

Commit 622195c

Browse files
authored
fix: ensure performance.now() and requestAnimationFrame() are polyfilled in ssr (#10715)
1 parent a5a566d commit 622195c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.changeset/pink-bikes-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: ensure performance.now() and requestAnimationFrame() are polyfilled in ssr
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import { noop } from '../common.js';
2+
3+
const is_client = typeof window !== 'undefined';
4+
5+
const request_animation_frame = is_client ? requestAnimationFrame : noop;
6+
7+
const now = is_client ? () => performance.now() : () => Date.now();
8+
19
/** @type {import('./types.js').Raf} */
210
export const raf = {
3-
tick: /** @param {any} _ */ (_) => requestAnimationFrame(_),
4-
now: () => performance.now()
11+
tick: /** @param {any} _ */ (_) => request_animation_frame(_),
12+
now: () => now()
513
};

0 commit comments

Comments
 (0)