svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Svelte5: Infinite loop (ERR_SVELTE_TOO_MANY_UPDATES: Maximum update depth exceeded)

Open rafales opened this issue 1 year ago • 2 comments

Describe the bug

I am running into an infinite loop with effects. I am 99.9% positive that this code should not result in one and that this is in fact a bug in svelte.

This code worked fine to next41 and broke in next42. It remains broken in next52.

Reproduction

  • Use this reproduction: https://stackblitz.com/edit/sveltejs-kit-template-default-1jlerd?file=src%2Froutes%2F%2Bpage.svelte
  • Open in new window, go to /repro route.
  • Use Chrome for this, locally it breaks in Safari, Chrome and Firefox, but I used Chrome to test this reproduction.

Logs

Error: ERR_SVELTE_TOO_MANY_UPDATES: Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops.
    infinite_loop_guard runtime.js:536
    flush_queued_effects runtime.js:554
    process_microtask runtime.js:588
    schedule_effect runtime.js:615
    mark_signal_consumers runtime.js:1147
    mark_signal_consumers runtime.js:1149
    update_derived runtime.js:811
    get runtime.js:970
    anySelected store.svelte.ts:5
    execute_signal_fn runtime.js:338
    update_derived runtime.js:804
    is_signal_dirty runtime.js:283
    flush_queued_effects runtime.js:563
    process_microtask runtime.js:588
    schedule_effect runtime.js:615
    mark_signal_consumers runtime.js:1147
    mark_signal_consumers runtime.js:1149
    update_derived runtime.js:811
    get runtime.js:970
    anySelected store.svelte.ts:5
    execute_signal_fn runtime.js:338
    update_derived runtime.js:804
    is_signal_dirty runtime.js:283
    flush_queued_effects runtime.js:563
    process_microtask runtime.js:588
    schedule_effect runtime.js:615
    mark_signal_consumers runtime.js:1147
    mark_signal_consumers runtime.js:1149
    update_derived runtime.js:811
    get runtime.js:970
    anySelected store.svelte.ts:5
    execute_signal_fn runtime.js:338
    update_derived runtime.js:804
    is_signal_dirty runtime.js:283
    flush_queued_effects runtime.js:563
    process_microtask runtime.js:588
    schedule_effect runtime.js:615
    mark_signal_consumers runtime.js:1147
    mark_signal_consumers runtime.js:1149
    update_derived runtime.js:811
    get runtime.js:970
    anySelected store.svelte.ts:5
    execute_signal_fn runtime.js:338
    update_derived runtime.js:804


### System Info

```shell
System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 95.69 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - /opt/homebrew/bin/npm
    Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 121.0.6167.160
    Safari: 17.2.1


Output is missing firefox 122.0.1 (64-bit).

Severity

blocking an upgrade

rafales avatar Feb 10 '24 11:02 rafales

Please can you provide a repro on the Svelte 5 REPL instead of stackblitz? Thanks

trueadm avatar Feb 12 '24 13:02 trueadm

@trueadm I don't see the option to run sveltekit there. Store creation needs to be in +page.ts, otherwise I'm not running into the problem. Maybe it's due to passing the data from an outer component or something, I don't know. I removed as much code as I could to still trigger the problem.

rafales avatar Feb 12 '24 15:02 rafales

Looks like this has since been fixed so closing now.

trueadm avatar Feb 23 '24 12:02 trueadm