Skip to content

Await reactivity loss warning when consuming the same state in two different queries #14113

@hugo-hsi-dev

Description

@hugo-hsi-dev

Describe the bug

OUTDATED:
The warning appears when I try to update global state that is accessed in a component and passed to a remote query. I have tried contexts and URL search params for my solution of global application state, both of which result in the same warning. Interestingly, this issue seems to only come up when I pass the global state to two queries or more queries at the same time. When isolating queries everything works just fine.

After some exploration, it seems that this issue is tied to queries, rather than the new await. I have seen no issues at all when passing global state to a client side only async function, hence why I'm raising the issue in the kit repo.

Here is the documentation to the warning message that I've been getting:
Warning Docs

Update:
I found out that this has nothing to do with context/global state. As long as two different queries rely on a single piece of state, the warning will show up.

Reproduction

Link to repo

Clone the source

pnpm install
pnpm run dev

Initially, to trigger the warning you would need to click the increment button to update the 'count' state. After updating svelte from 5.37.3 to 5.38.0 and sveltekit from 2.27.0 to 2.27.1, I get the warning spam shown in the screenshot below.

Here's the code in a nutshell

<!-- Component -->
<script>
    import { returnCount, returnDouble } from "./return-count.remote";

    let count = $state(0);
</script>

<svelte:boundary>
    <div>Return Count: {await returnCount(count)}</div>
    <div>Return Double: {await returnDouble(count)}</div>
    {#snippet pending()}
        loading...
    {/snippet}
</svelte:boundary>
<button onclick={() => count++}>Increment</button>
// Remotes
import { query } from "$app/server";

export const returnCount = query("unchecked", async (count: number) => {
  // To simulate network delay
  await new Promise((resolve) => setTimeout(resolve, 300));
  return count;
});

export const returnDouble = query("unchecked", async (count: number) => {
  // To simulate network delay
  await new Promise((resolve) => setTimeout(resolve, 300));
  return count * 2;
});

gif of basic reproduction
gif of desynced state reproduction

Logs

OUTDATED:

First warning: 
[svelte] await_reactivity_lossDetected reactivity loss when reading `undefined`. This happens when state is read in an async function after an earlier `await`https://svelte.dev/e/await_reactivity_loss

Second warning: 
TracedAtError
    at get_stack (tracing.js:137:14)
    at get (runtime.js:596:17)
    at Array.map (<anonymous>)
    at effects.js:356:51
    at update_reaction (runtime.js:287:53)
    at update_effect (runtime.js:467:18)
    at flush_queued_effects (batch.js:603:4)
    at _Batch.process (batch.js:232:4)
    at flush_effects (batch.js:561:10)
    at _Batch.flush (batch.js:381:4)

Update: After updating dependencies, to see if things got fixed in other pr's I'm getting different warning messages.

First warning: 
[svelte] await_reactivity_lossDetected reactivity loss when reading `Query.#current`. This happens when state is read in an async function after an earlier `await`

Second warning: 
TracedAtError
    at get_stack (tracing.js:137:14)
    at Module.get (runtime.js:596:17)
    at Query.<anonymous> (query.svelte.js:73:12)

... and many more

Image

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 19.61 GB / 31.95 GB
  Binaries:
    Node: 22.16.0 - ~\scoop\apps\nodejs-lts\current\node.EXE
    npm: 10.9.2 - ~\scoop\apps\nodejs-lts\current\npm.CMD
    pnpm: 10.13.1 - ~\scoop\shims\pnpm.EXE
    bun: 1.2.19 - ~\scoop\shims\bun.EXE
  Browsers:
    Edge: Chromium (137.0.3296.83)
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.0.1
    @sveltejs/kit: ^2.22.0 => 2.27.0
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.1.0
    svelte: ^5.0.0 => 5.37.3
    vite: ^7.0.4 => 7.0.6

Severity

blocking an upgrade

Additional Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions