treat requestAnimationFrame as a noop on the server

pull/2856/head
Rich Harris 5 years ago
parent 298ae8ec23
commit a5fe09c481

2
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "svelte",
"version": "3.4.0",
"version": "3.4.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -455,7 +455,7 @@ export default class ElementWrapper extends Wrapper {
function ${handler}() {
${animation_frame && deindent`
cancelAnimationFrame(${animation_frame});
if (!${this.var}.paused) ${animation_frame} = requestAnimationFrame(${handler});`}
if (!${this.var}.paused) ${animation_frame} = @raf(${handler});`}
${needs_lock && `${lock} = true;`}
ctx.${handler}.call(${this.var}${contextual_dependencies.size > 0 ? ', ctx' : ''});
}

@ -1,4 +1,4 @@
import { now } from './utils.js';
import { now, raf } from './utils.js';
const tasks = new Set();
let running = false;
@ -12,7 +12,7 @@ function run_tasks() {
});
running = tasks.size > 0;
if (running) requestAnimationFrame(run_tasks);
if (running) raf(run_tasks);
}
export function clear_loops() {
@ -26,7 +26,7 @@ export function loop(fn) {
if (!running) {
running = true;
requestAnimationFrame(run_tasks);
raf(run_tasks);
}
return {

@ -1,4 +1,5 @@
import { element } from './dom.js';
import { raf } from './utils.js';
let stylesheet;
let active = 0;
@ -56,7 +57,7 @@ export function delete_rule(node, name) {
}
export function clear_rules() {
requestAnimationFrame(() => {
raf(() => {
if (active) return;
let i = stylesheet.cssRules.length;
while (i--) stylesheet.deleteRule(i);

@ -80,11 +80,15 @@ export function exclude_internal_props(props) {
return result;
}
export let now = typeof window !== 'undefined'
const is_client = typeof window !== 'undefined';
export let now = is_client
? () => window.performance.now()
: () => Date.now();
// used internally for testing
export function set_now(fn) {
now = fn;
}
}
export const raf = is_client ? requestAnimationFrame : noop;
Loading…
Cancel
Save