query() does not decode X-Server-Function-Redirect, so a redirect() thrown inside a "use server" read only redirects during SSR
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- full-stack
Research direction
Start in src/data/query.ts, especially handleResponse, and compare its redirect handling with src/data/action.ts and decodeRedirectHeaderValue. Run test/query-redirect.spec.tsx, then reproduce the client-side navigation case from the issue. Done means query handles X-Server-Function-Redirect like action, including same-origin navigation and a pending client read.
Written by the indexing model from the issue text.
Description
Branch: next (f7602bf), against solid next (344ed054).
Summary
A redirect() thrown or returned inside a "use server" function that is wrapped in query() redirects on a full page request but not on a client-side navigation. The read settles with the Response object as its value and the navigation completes as if the check had passed.
Why
- The server-function transport masks redirects for scripted callers:
maskRedirectcopies the target intoX-Server-Function-Redirect(<status> <absolute-url>) and deletesLocation(solid/packages/web/server-functions/src/server.ts~2028–2034). - The client transport returns such a response whole, untouched, for the integration to decode (
solid/packages/web/server-functions/src/client.ts~744–757). query.ts'shandleResponseonly checksv.headers.get("Location")before navigating (src/data/query.ts~268–300). WithLocationgone, it falls through and the Response becomes the query's value.action.tsdoes decode the carrier (decodeRedirectHeaderValue(metadata.headers.get(REDIRECT_HEADER)),src/data/action.ts~473), which is why the samethrow redirect()works from a router action.
test/query-redirect.spec.tsx covers a thrown Response that still carries Location, which is the SSR / in-process shape, so the gap is not exercised.
Repro
// src/data/account.ts
export const requireUser = query(async () => {
"use server";
const userId = getRequestEvent()?.locals.userId;
if (!userId) throw redirect("/sign-in");
return database.customers.find(userId);
}, "require-user");
Read requireUser() from a route preload or a memo under /account.
- Load
/accountsigned out with a full request: 302 to/sign-in. ✅ - Navigate to
/accountsigned out from another route (client-side): no navigation; the memo's value is aResponse. ❌
Expected
query should treat a response carrying X-Server-Function-Redirect the way action does: decode it with decodeRedirectHeaderValue, navigate softly for same-origin targets, and hold the read pending on the client.
Workaround (what the docs currently describe)
Throw the redirect in the function query wraps, with the server function inside it:
export const requireUser = query(async () => {
const user = await getCurrentUser(); // "use server"
if (!user) throw redirect("/sign-in");
return user;
}, "require-user");
The docs' Protected routes guide documents this shape with a caution explaining the limitation; once query decodes the carrier, that caution can be removed.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 180
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 19
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs/solid-router
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
solidjs/solid-router#605 · 1 comment ·
-
<A> costs ~6us of server CPU per instance during SSR (20x a plain <a>), mostly mergeProps/splitProps Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
solidjs/solid-router#583 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
solidjs/solid-router#569 · 3 comments ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 38/100
solidjs/solid-router#518 · 2 comments ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 64/100
solidjs/solid-router#502 · 4 comments ·
All issues in solidjs/solid-router
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·