sveltejs / sveltejs/kit

Remote Functions: query().loading is not updating or is not reactive.

Open
#14,915 3 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

This should reactively flip from true to false but does not.

   // Stays true
    const isALoading = $derived(queryA().loading);

Doing this instead works as expected:

   // Flips from true -> false
   const a = queryA();
   const isALoading = $derived(a.loading);
Reproduction

Repo reproduction

Logs
Console logs:

+page.svelte:8 true 'A loading'
+page.svelte:9 true 'B loading'
+page.svelte:9 false 'B loading'
chunk-DHS26EHK.js?v=264bc703:413 stack trace
chunk-DHS26EHK.js?v=264bc703:414 $inspect(...)
    at query.svelte.js?v=264bc703:241:6
Severity

serious, but I can work around it

Additional Information

Thanks for building!

Also, is it best practice to set the remote functions to a const const remote = myQuery(); remote.set(...) or use it directly from import: myQuery().set(..)?

I prefer the latter (direct use) because it makes searching for uses of a remote function easier across a code base.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction at src/routes/+page.svelte and reproduce the differing behavior between $derived(queryA().loading) and the stored query result. Trace the reported stack through query.svelte.js, then verify that loading changes from true to false reactively for direct calls while the working stored form remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.