Skip to content

Batch has scheduled roots #18126

@felixf2k

Description

@felixf2k

Describe the bug

I've gotten this invariant_violation error in a bigger Project, but this is the smallest reproduction i was able to create.

The error gets thrown when:

  1. A page queries and awaits data using a remote query
  2. A remote form gets submitted (not a single-flight mutation)
  3. In the enhance function of the form a $state gets set after await submit() has run

If any of the above are not true the error doesn't occur (e.g. the form invalidates the query, the state gets set before the submit function runs)

Reproduction

https://github.com/felixf2k/bug-invariant-violation

Logs

Uncaught Svelte error: invariant_violation
An invariant violation occurred, meaning Svelte's internal assumptions were flawed. This is a bug in Svelte, not your app — please open an issue at https://github.com/sveltejs/svelte, citing the following message: "Batch has scheduled roots"
https://svelte.dev/e/invariant_violation
    at invariant_violation (runtime-daVIWO85.js?v=3d3391a3:191:33)
    at invariant (runtime-daVIWO85.js?v=3d3391a3:934:18)
    at #commit (runtime-daVIWO85.js?v=3d3391a3:2000:5)
    at #process (runtime-daVIWO85.js?v=3d3391a3:1886:58)
    at Batch.flush (runtime-daVIWO85.js?v=3d3391a3:1958:17)
    at Array.<anonymous> (runtime-daVIWO85.js?v=3d3391a3:2063:9)
    at run_all (runtime-daVIWO85.js?v=3d3391a3:39:45)
    at run_micro_tasks (runtime-daVIWO85.js?v=3d3391a3:1139:2)
    at runtime-daVIWO85.js?v=3d3391a3:1148:31

System Info

System:
    OS: Linux 6.18 cpe:/o:nixos:nixos:26.05 26.05 (Yarara)
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
    Memory: 11.33 GB / 31.04 GB
    Container: Yes
    Shell: 5.3.9 - /run/current-system/sw/bin/bash
  Binaries:
    Node: 24.14.0 - /etc/profiles/per-user/felix/bin/node
    npm: 11.9.0 - /etc/profiles/per-user/felix/bin/npm
    pnpm: 10.33.0 - /etc/profiles/per-user/felix/bin/pnpm
  Browsers:
    Chromium: 146.0.7680.177
    Firefox: 149.0
    Firefox Developer Edition: 149.0
  npmPackages:
    svelte: ^5.55.2 => 5.55.4

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions