Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
Describe the bug
After a server action completes, the single-flight re-run of the route preload receives a request whose Cookie header has cookies joined with ", " instead of "; ". Cookie parsers then see a single cookie, so auth libraries cannot find the session cookie and treat the user as signed out.
This only happens on the built app under Wrangler (Cloudflare Workers runtime). It does not happen on the Vite dev server.
Observed
Inside a query called from a route preload, during the post-action re-run:
- getRequestEvent().request.method is GET
- request.headers.get("cookie") is: sidebar_collapsed=true, theme=system, app.session_token=REDACTED, app.session_data=REDACTED
On a normal page request the same header is ; separated and works. The session token value also appears URL-decoded in the rebuilt header (raw + and =), which may be a related problem.
Expected
The re-run request carries a valid Cookie header (name=value; name2=value2), the same as a browser request would.
Impact
With better-auth, auth.api.getSession({ headers }) returns null during the re-run. A layout gated on that query receives null and renders nothing, so the page goes blank after any action with default revalidation.
Reproduction
- Route with a preload that calls a query reading the session from
getRequestEvent().request.headers. - Have at least two cookies set in the browser.
- Fire any server action from that route (default revalidation).
- Build and run with wrangler dev [and/or --remote].
- Log the cookie header inside the query during the re-run.
Workaround
Normalize the header before passing it to the auth library: cookie.replace(/, (?=[^;,=\s]+=)/g, "; ") Or limit revalidation per action so the preload query does not re-run.
Environment
- "@solidjs/start": "^2.0.0",
- "solid-js": "^1.9.5",
- "@solidjs/router": "^1.0.1",
- Deployment preset: [e.g. cloudflare-module]
- "wrangler": "^4.59.3"
- "compatibility_date": "2025-09-27",
- Auth: "better-auth": "^1.6.23",
- Browser / OS: Firefox on macOS and Safari]
Activity