sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.18k stars 4.08k forks source link

Running many animations on timer when the tab is in background causes a memory leak #9865

Open angryziber opened 9 months ago

angryziber commented 9 months ago

Describe the bug

Probably because Chrome throttles timers/rendering when tab is not active.

Reproduction

Run many e.g. flip animations when the browser tab is not active and it eventually crashes.

Probably all animation functions should check for document.visibilityState === 'visible' before they are run, this will save CPU and memory when tabs are not active.

Logs

No response

System Info

Chrome 120

Severity

annoyance

trueadm commented 9 months ago

Is this for Svelte 4 or Svelte 5?

angryziber commented 9 months ago

Svelte 4

angryziber commented 9 months ago

We are using the following workaround now:

export const flipIfVisible: typeof flip = (...args) => (document.visibilityState === 'visible' ? flip(...args) : {});