fix(router): restore .fail() behavior#8756
Merged
Merged
Conversation
This is the previous behavior for backwards compatibility
🦋 Changeset detectedLatest commit: 108fb66 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
@qwik.dev/core
@qwik.dev/router
eslint-plugin-qwik
create-qwik
@qwik.dev/optimizer
commit: |
There was a problem hiding this comment.
Pull request overview
Restores Qwik Router routeLoader$().fail() backward-compatible behavior by treating fail() results as plain loader data instead of routing them through the loader JSON error envelope.
Changes:
- Updated
getRouteLoaderResponse()to always returnfail()results in thed(data) channel and reserveefor thrownServerErrors. - Adjusted loader JSON caching logic to treat
fail()responses as non-cacheable. - Updated docs and added unit coverage for the loader response envelope behavior; added a router changeset.
Focused security / trust-boundary check
- Boundary changed: loader JSON response shaping (
{ d, r, e }) and caching decisions in the request handler. - Guard/invariant: redirects/errors are still represented via
r/e(with thrownServerErrors only), and loader execution remains wrapped bygetRouteLoaderResponse()/jsonRequestWrapper()to prevent raw errors from leaking into SPA navigation. - Coverage: added unit tests around
getRouteLoaderResponse()envelope behavior; loader-handler caching behavior should be covered by an additional handler unit test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/qwik-router/src/runtime/src/route-loaders.unit.ts | Adds unit tests asserting fail() stays in d and thrown ServerError maps to e. |
| packages/qwik-router/src/runtime/src/route-loaders.ts | Changes loader JSON envelope behavior so fail() is treated as plain data; updates type docs. |
| packages/qwik-router/src/middleware/request-handler/handlers/loader-handler.ts | Updates caching decision logic to avoid caching fail() results. |
| packages/docs/src/routes/docs/(qwikrouter)/route-loader/index.mdx | Updates docs to explain inline fail() vs thrown error() behavior. |
| .changeset/loader-fail-value.md | Adds a patch changeset documenting the restored fail() behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+95
to
+98
| // Only successful data envelopes are cacheable; never cache redirects, errors, or fail() results. | ||
| const failed = | ||
| responseData.d && typeof responseData.d === 'object' && (responseData.d as any).failed; | ||
| const cacheable = cacheKey && !responseData.r && !responseData.e && !failed; |
Comment on lines
+97
to
+98
| - **`throw requestEvent.error(status, data)`** — throw a `ServerError` directly. `signal.error` is `ServerError {status, data}`. Reading `signal.value` re-throws the error, so you should branch on `signal.error` first. This is the recommended way to signal failure from a loader. | ||
| - **`return requestEvent.fail(status, data)`** — returns an inline failure. `signal.value.failed` is `true` and `signal.value` contains the rest of the data. |
| - **`throw requestEvent.error(status, data)`** — throw a `ServerError` directly. `signal.error` is `ServerError {status, data}`. Reading `signal.value` re-throws the error, so you should branch on `signal.error` first. This is the recommended way to signal failure from a loader. | ||
| - **`return requestEvent.fail(status, data)`** — returns an inline failure. `signal.value.failed` is `true` and `signal.value` contains the rest of the data. | ||
|
|
||
| In both cases, the HTTP response status is set to `status`, and the result is not cacheable. |
Contributor
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
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.
For backwards compatibility