Skip to content

feat(router): ev.internalRequest information#8698

Merged
wmertens merged 2 commits into
build/v2from
requestev-internal
Jun 7, 2026
Merged

feat(router): ev.internalRequest information#8698
wmertens merged 2 commits into
build/v2from
requestev-internal

Conversation

@wmertens

@wmertens wmertens commented Jun 5, 2026

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 5, 2026 14:00
@wmertens wmertens requested review from a team as code owners June 5, 2026 14:00
@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 27505d5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@qwik.dev/router Patch
eslint-plugin-qwik Patch
@qwik.dev/core Patch
create-qwik Patch
@qwik.dev/react Patch

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

@maiieul maiieul moved this to Waiting For Review in Qwik Development Jun 5, 2026
@wmertens wmertens changed the title fix(router): ensure that redirects are converted to json feat(router): ev.internalRequest information Jun 5, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8698

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8698

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8698

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8698

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8698

commit: 27505d5

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves Qwik Router’s handling of internal JSON requests (q-loader and fetch-based qaction), ensuring redirects are surfaced to the client as loader/action-compatible JSON signals and giving middleware better context to avoid accidentally rewriting internal requests.

Changes:

  • Convert unfollowed HTTP 3xx responses from loader fetches into { r: location } loader redirect envelopes.
  • Route q-loader requests through the page’s middleware chain by validating and honoring X-Qwik-fullpath.
  • Expose RequestEvent.internalRequest (false | 'loader' | 'action') across runtime types, middleware types, and documentation.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/qwik-router/src/runtime/src/use-endpoint.unit.ts Adds a regression test asserting 3xx loader fetches are converted into loader redirect envelopes.
packages/qwik-router/src/runtime/src/types.ts Re-exports the new InternalRequest type from middleware for runtime consumers.
packages/qwik-router/src/runtime/src/route-loaders.ts Adds 3xx/Location handling in fetchRouteLoaderData() for unfollowed redirects.
packages/qwik-router/src/runtime/src/qwik-router.runtime.api.md Updates the API report to include InternalRequest in the runtime surface.
packages/qwik-router/src/runtime/src/index.ts Exports InternalRequest from the runtime entrypoint.
packages/qwik-router/src/middleware/request-handler/types.ts Introduces InternalRequest and adds internalRequest to RequestEventBase.
packages/qwik-router/src/middleware/request-handler/request-path.unit.ts Adds tests for validating internal full pathnames used by q-loader routing.
packages/qwik-router/src/middleware/request-handler/request-path.ts Adds resolveValidInternalFullPathname() helper for safe X-Qwik-fullpath usage.
packages/qwik-router/src/middleware/request-handler/request-handler.unit.ts Tests getRequestHandlerPathname() behavior for q-loader vs normal page requests.
packages/qwik-router/src/middleware/request-handler/request-handler.ts Routes q-loader requests based on validated X-Qwik-fullpath (when applicable).
packages/qwik-router/src/middleware/request-handler/request-event.unit.ts Adds unit tests for RequestEvent.internalRequest detection semantics.
packages/qwik-router/src/middleware/request-handler/request-event-core.ts Implements internalRequest getter on the request event instance.
packages/qwik-router/src/middleware/request-handler/middleware.request-handler.api.md Updates the middleware API report with InternalRequest and internalRequest.
packages/qwik-router/src/middleware/request-handler/index.ts Re-exports InternalRequest from the middleware entrypoint.
packages/qwik-router/src/middleware/request-handler/handlers/json-request-wrapper.unit.ts Tests that loader middleware redirects are serialized into loader JSON redirect envelopes.
packages/qwik-router/src/middleware/request-handler/handlers/json-request-wrapper.ts Uses shared validation helper and serializes loader redirects into JSON envelopes.
packages/docs/src/routes/docs/(qwikrouter)/routing/index.mdx Documents internalRequest on RequestEvent.
packages/docs/src/routes/docs/(qwikrouter)/middleware/index.mdx Adds a dedicated internalRequest documentation section.
packages/docs/src/routes/docs/(qwikrouter)/guides/rewrites/index.mdx Updates rewrite guidance to guard against rewriting internal JSON requests.
packages/docs/src/routes/docs/(qwikrouter)/advanced/request-handling/index.mdx Adds internalRequest to the request event overview table.
packages/docs/src/routes/api/qwik-router-middleware-request-handler/index.mdx Updates generated API docs for InternalRequest and RequestEventBase.internalRequest.
packages/docs/src/routes/api/qwik-router-middleware-request-handler/api.json Updates generated API JSON to include InternalRequest and internalRequest.
.changeset/router-loader-redirects.md Adds a patch changeset for q-loader middleware chain + unfollowed redirect handling.
.changeset/router-internal-request.md Adds a patch changeset for exposing RequestEvent.internalRequest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Varixo Varixo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview f0c64b3

import type { RequestHandler } from '@qwik.dev/router';

export const onRequest: RequestHandler = async ({ url, rewrite, internalRequest }) => {
if (internalRequest) {

@maiieul maiieul Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there really no better alternatives? This is not so great DX wise since devs must know about it... Ideally redirects should just work without having to remember to check for internal requests.

@wmertens wmertens Jun 7, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's impossible:

Either middleware doesn't run for loader requests, and it will miss logged-in state etc,
or the dev always redirects even for loaders, which breaks things.

This is because now each loader gets its own request, which allows sane loader caching.

In any case, no matter which API we would use, we still need to educate the dev. Having a prop directly visible in the type on requestEv is the most direct thing we can do.

@wmertens wmertens enabled auto-merge June 7, 2026 09:59
@wmertens wmertens force-pushed the requestev-internal branch from f0c64b3 to 27505d5 Compare June 7, 2026 10:12
@wmertens wmertens merged commit a3c6e49 into build/v2 Jun 7, 2026
23 checks passed
@wmertens wmertens deleted the requestev-internal branch June 7, 2026 10:14
@github-project-automation github-project-automation Bot moved this from Waiting For Review to Done in Qwik Development Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants