fix: serialize query values seeded with .set() during SSR - #16428
Closed
Nic-Polumeyv wants to merge 3 commits into
Closed
fix: serialize query values seeded with .set() during SSR#16428Nic-Polumeyv wants to merge 3 commits into
.set() during SSR#16428Nic-Polumeyv wants to merge 3 commits into
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/9f76db683092ff9ee32ceb68926b705ca40e95d6Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 9f76db6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Nic-Polumeyv
force-pushed
the
fix-query-set-ssr-serialization
branch
from
July 19, 2026 19:19
db7a708 to
9f76db6
Compare
Nic-Polumeyv
marked this pull request as ready for review
July 19, 2026 20:00
Contributor
|
In reviewing this I realized we weren't handling refreshes correctly in the first place: #16461 |
elliott-with-the-longest-name-on-github
added a commit
that referenced
this pull request
Jul 22, 2026
Supersedes #16428. It had the right approach, but we were actually handling `refresh` wrong in the first place. I thought we'd implemented this behavior but somehow we haven't. Anyway, this kills two birds with one stone: - It makes sure we allow `.refresh` (and `.set`) to run during render - It makes `.refresh` lazy: Calling `.refresh` busts the cache and guarantees that the cache will be populated by the end of the request. If you `await` the query or access its data, it will immediately run and populate the cache; otherwise SvelteKit will do it at the end of the request, in parallel with any other refreshing queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #16384
During SSR, calling
otherQuery(arg).set(value)inside a query populates the request cache but never reaches the serialized payload, so the client refetches data the server already had. The same call during a client-initiated request is included in the endpoint response and reused without a network call.The cause is the
!event.isRemoteRequestguard in therefresh()helper. It was added in #15803 for non-enhanced form submissions, where refreshing queries is pointless because the page re-renders. At that time.set()outside a form/command threw, so the guard could not affect queries. #15991 removed that error as part of the serialization rework, which made.set()inside queries legal and serialized on the endpoint path, while the SSR render path still hit the old guard and silently dropped the registration.The render already serializes
state.remote.explicitand the client already seeds its cache from the SSR payload, so the fix narrows the guard to the case #15803 actually targeted, a form or command running outside a remote request. Non-enhanced form submissions behave as before, including the noop refresh test added in #15803.Two side effects of the narrowed guard, both consistent with the endpoint path but worth ruling on knowingly.
.set()and.refresh()called from a server or universal load during SSR now also serialize. The SSR payload gainsr: truewhen explicit entries exist, which the client start code ignores.Tests mirror the reporter's reproduction. A list query seeds per-item detail queries, the server test asserts the seeded values appear in the SSR HTML, and the client test asserts a client-side navigation renders the seeded value with zero remote requests.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits