sveltejs / svelte

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

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

Closed rafales closed 6 months ago

rafales commented 7 months ago

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

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

trueadm commented 7 months ago

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

rafales commented 7 months ago

@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.

trueadm commented 6 months ago

Looks like this has since been fixed so closing now.