sveltejs / sveltejs/kit

Refreshing an upstream remote query doesn't refresh the dependent queries

Open
#15,912 12 comments 2 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

If I have a remote query like this:

export const get_foo = query(async () => {
	const foo = db.get_foo();
	return foo;
});

And then I have another remote query that depends onget_foo():

export const get_bar = query(async () => {
	const foo = await get_foo();

	const bar = db.get_bar(foo);
	return bar;
});

If I refresh the get_foo() query value, get_bar() is not automatically refreshed.

export const set_foo = form(
	v.object({
		foo: v.string()
	}),
	async ({ foo }) => {
		await db.set_foo(foo);
		get_foo().set(foo); // I would expect this to automatically also refresh `get_bar()` because it depends on `get_foo()`
	}
);

I would expect that to happen automatically?
Otherwise I need to manually define all the dependencies that must be refreshed, which will be a huge scalability problem 🤔

export const set_foo = form(
	v.object({
		foo: v.string()
	}),
	async ({ foo }) => {
		await db.set_foo(foo);
		get_foo().set(foo);
+		get_bar().refresh(); // This seems unnecessary, but it's currently the only way to make it work
	}
);
Reproduction

Example above has all info, but I can share a small repro codebase.

Logs

System Info
System:
    OS: macOS 26.5
    CPU: (8) arm64 Apple M3
    Memory: 78.47 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.15.0 - /Users/alexiglesiaspinol/.nvm/versions/node/v24.15.0/bin/node
    npm: 11.12.1 - /Users/alexiglesiaspinol/.nvm/versions/node/v24.15.0/bin/npm
    pnpm: 10.33.2 - /Users/alexiglesiaspinol/Library/pnpm/pnpm
  Browsers:
    Chrome: 148.0.7778.179
    Firefox: 148.0
    Safari: 26.5
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.1 => 7.0.1 
    @sveltejs/kit: ^2.61.1 => 2.61.1 
    @sveltejs/vite-plugin-svelte: ^7.1.2 => 7.1.2 
    svelte: 5.55.9 => 5.55.9 
    vite: ^8.0.14 => 8.0.14
Severity

serious, but I can work around it

Additional Information

No response

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 by tracing how remote queries record dependencies and how get_foo().set() invalidates dependents; inspect the query and form implementation plus existing refresh tests. Add a regression test for get_foo and get_bar, and verify that setting get_foo refreshes get_bar without a manual refresh.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
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.