diff --git a/.changeset/small-bobcats-add.md b/.changeset/small-bobcats-add.md new file mode 100644 index 0000000000..2bd686c9c1 --- /dev/null +++ b/.changeset/small-bobcats-add.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: don't access `requestAnimationFrame` until needed to reduce need for mocks during testing diff --git a/packages/svelte/src/internal/client/timing.js b/packages/svelte/src/internal/client/timing.js index 18dfc6c583..1702798952 100644 --- a/packages/svelte/src/internal/client/timing.js +++ b/packages/svelte/src/internal/client/timing.js @@ -7,6 +7,9 @@ const now = BROWSER ? () => performance.now() : () => Date.now(); /** @type {Raf} */ export const raf = { + // don't access requestAnimationFrame eagerly outside method + // this allows basic testing of user code without JSDOM + // bunder will eval and remove ternary when the user's app is built tick: /** @param {any} _ */ (_) => (BROWSER ? requestAnimationFrame : noop)(_), now: () => now(), tasks: new Set()