Skip to content

fix(solid-v2): pass the request event to createAPIHandler - #337

Merged
ryansolid merged 1 commit into
mainfrom
claude/project-thread-ij5fqc
Nov 4, 2026
Merged

ryansolid merged 1 commit into
mainfrom
claude/project-thread-ij5fqc

Conversation

@ryansolid

Copy link
Copy Markdown
Member

Requested by Ryan · project thread

Problem

On StackBlitz the solid-v2/fullstack template's API routes throw:

API route dispatched outside a request-event scope. Compose the handler inside provideRequestEvent (any ssr.middleware-style chain already is), or pass getEvent.

The template pinned filesystem-routing@0.4.0 and adapted the handler as (event, next) => api(event.request, next). With a bare Request, createAPIHandler finds the event through the AsyncLocalStorage that provideRequestEvent sets up. The plugin does run middleware inside that scope, and on plain Node it works. On StackBlitz (WebContainers) the store is lost across the handler's await import(), so the lookup fails.

Fix

filesystem-routing 0.4.1+ (solidjs/filesystem-routing#22) already accepts the request event as the first argument and hands that same event to the handler. The middleware becomes:

export default [createAPIHandler(routes)] satisfies StartMiddleware[];

No adapter, no cast, no getEvent, and API dispatch no longer depends on AsyncLocalStorage. satisfies keeps the type check against the plugin's middleware type.

  • fullstack and fullstack-tanstack: simplified src/middleware.ts; README line updated.
  • Every solid-v2 template: filesystem-routing 0.4.0 → 0.4.2, lockfiles updated, and file-routes.d.ts regenerated (0.4.2 emits the narrower Pick<...> ref types; dev rewrites the file anyway).

No change needed in filesystem-routing or @solidjs/vite-plugin.

Verified

  • Reproduced the exact error locally by preloading a stub that makes AsyncLocalStorage#getStore() return undefined (as on StackBlitz): old template → 500 with this message; new template → 200 on /api/users.
  • Normal dev: /api/users → 200 in fullstack and fullstack-tanstack; fullstack production build + node dist/server/node.js → 200.
  • tsc --noEmit clean in both fullstack templates; fullstack vitest 11/11 passing; vite build passes in every template whose types were regenerated.

Generated by Claude Code

The fullstack templates pinned filesystem-routing 0.4.0 and adapted
createAPIHandler with (event, next) => api(event.request, next). Given a
bare Request, the handler looks the event up through AsyncLocalStorage,
which is lost on StackBlitz (WebContainers), so API routes threw
"API route dispatched outside a request-event scope".

filesystem-routing 0.4.1+ accepts the request event directly, so the
middleware is now just [createAPIHandler(routes)] and no longer depends
on AsyncLocalStorage. Bump every solid-v2 template to 0.4.2 and commit
the route types it generates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117BoWMMegDebEwDZnRWWC2
@ryansolid ryansolid self-assigned this Nov 4, 2026
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedfilesystem-routing@​0.4.0 ⏵ 0.4.298 +8100100 +191100

View full report

@ryansolid
ryansolid merged commit a7dca82 into main Nov 4, 2026
2 checks passed
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.

2 participants