fix: ensure performance.now() and requestAnimationFrame() are polyfilled in ssr (#10715)

pull/10718/head
Dominic Gannaway 2 years ago committed by GitHub
parent a5a566dfa7
commit 622195cc21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: ensure performance.now() and requestAnimationFrame() are polyfilled in ssr

@ -1,5 +1,13 @@
import { noop } from '../common.js';
const is_client = typeof window !== 'undefined';
const request_animation_frame = is_client ? requestAnimationFrame : noop;
const now = is_client ? () => performance.now() : () => Date.now();
/** @type {import('./types.js').Raf} */
export const raf = {
tick: /** @param {any} _ */ (_) => requestAnimationFrame(_),
now: () => performance.now()
tick: /** @param {any} _ */ (_) => request_animation_frame(_),
now: () => now()
};

Loading…
Cancel
Save