Skip to content

docs: show start-mode middleware as (event, next) - #1717

Open
VedangP57 wants to merge 1 commit into
solidjs:v2-rebuildfrom
VedangP57:docs/middleware-event-first
Open

VedangP57 wants to merge 1 commit into
solidjs:v2-rebuildfrom
VedangP57:docs/middleware-event-first

Conversation

@VedangP57

Copy link
Copy Markdown
  • I have read the Contribution guide
  • This PR references an issue (except for typos, broken links, or other minor problems)

Description(required)

Since @solidjs/vite-plugin 3.0.0-next.48, start-mode middleware is (event, next) (StartMiddleware), the request is event.request, and next() takes no arguments. Several pages still showed the earlier (request, next) shape and next(request). Copied as written, they break the app: the first argument is the event, so request.url is undefined, and next(request) turns every page into a 500.

Changes:

  • Middleware and API routes: the middleware type, every example (attachCustomer, securityHeaders, requireHttps, catchErrors), the "replace the request" paragraph (now: assign event.request, with an example), the deep-dive line and the recap. The module export uses satisfies StartMiddleware[] like the fullstack template.
  • Protected routes: requireAccountSession reads event.request and event.locals.
  • Sessions and auth: attachCustomer writes event.locals.
  • StartOptions reference: the middleware type, plus three lines on event.request, next() and per-request render inputs.
  • Redirects in examples use redirect() from @solidjs/web instead of Response.redirect(). Response.redirect() returns immutable headers. With the guide's securityHeaders earlier in the chain, a guard's redirect (the protected-routes one, for example) threw a TypeError and answered 500. Verified in dev. Two "Common problems" entries cover both errors.

I left out the filesystem-routing/api reference. Its source_ref is v0.2.1, and in 0.5.0 createAPIHandler takes Request | { request }, so it works in the chain either way. It probably wants a re-sync rather than a hand edit.

How I checked it (solid-js / @solidjs/web 2.0.3, @solidjs/vite-plugin 3.0.1, filesystem-routing 0.5.0):

  • The new snippets, assembled into one src/middleware.ts with createAPIHandler(routes) at the end, type-check as StartMiddleware[] with 0 errors. Only getSession and the sign-in path were stubbed.
  • Under vite dev: / returns 200 with x-frame-options: DENY; /account/orders?x=1 signed out returns 302 to /sign-in?next=%2Faccount%2Forders%3Fx%3D1, with the header; the event.request rewrite serves the target page; no errors are logged.
  • Before the change, the same chain using Response.redirect() answered that guarded request with 500 (TypeError: immutable).
  • prettier --check on the changed files, pnpm lint:tone (0 errors) and pnpm check:types pass, and the four pages render under vite dev.

Related issues & labels

🤖 Generated with Claude Code

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@netlify

netlify Bot commented Nov 19, 2026

Copy link
Copy Markdown

👷 Deploy request for solid-docs-v2 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 707c82b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant