Repository navigation
fix(router): reject server$ calls that get a non-server$ response - #9378
Conversation
server$ compared the whole Content-Type header, so 'text/html; charset=utf-8' (e.g. a page after a middleware redirect) matched no branch and the call resolved undefined. Compare only the media type and throw for anything that is not a server$ payload. Fixes QwikDev#9335
🦋 Changeset detectedLatest commit: c12cf1c The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@qwik.dev/core
@qwik.dev/router
@qwik.dev/utils
eslint-plugin-qwik
create-qwik
@qwik.dev/optimizer
@qwik.dev/devtools
@qwik.dev/mcp
commit: |
|
⚡ Docs preview for c12cf1c |
Summary
When a
server$request was answered with an HTML page (for example a middleware redirecting?qfunc=requests to/on an expired session), the call resolvedundefined. The client compared the wholeContent-Typeheader, sotext/html; charset=utf-8matched none of the branches and the function just fell off the end. The same happened forapplication/json; charset=utf-8andtext/plain; charset=utf-8, which is whatjson()andtext()in a request handler send.Fix
serverQrlintoreadServerFunctionResponseso it can be unit tested (in the vitest setupisServeris replaced at compile time, so I couldn't drive the client branch throughserver$itself).text/htmlfrom the string branch. It's not in theAcceptheader the client sends, so it's never aserver$payload. Anything that doesn't match now throws an error with the status and content type, so the promise rejects.Testing
pnpm vitest run packages/qwik-router/src/runtime/src/server-functions.unit.ts; charset=utf-8still resolving or throwing on 4xx. Both fail on main and pass with this change.Fixes #9335
All qwik-router unit tests pass (885). The only failures in the full
test.unitrun here are the qwik-vite optimizer tests, which need the native optimizer binding I do not have built locally.Summary by CodeRabbit
server$calls now reject unexpected responses, such as HTML pages, instead of resolving toundefined.