Repository navigation
fix(solid-v2): pass the request event to createAPIHandler - #337
Merged
Merged
Conversation
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
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Requested by Ryan · project thread
Problem
On StackBlitz the
solid-v2/fullstacktemplate's API routes throw:The template pinned
filesystem-routing@0.4.0and adapted the handler as(event, next) => api(event.request, next). With a bareRequest,createAPIHandlerfinds the event through theAsyncLocalStoragethatprovideRequestEventsets 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'sawait import(), so the lookup fails.Fix
filesystem-routing0.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:No adapter, no cast, no
getEvent, and API dispatch no longer depends onAsyncLocalStorage.satisfieskeeps the type check against the plugin's middleware type.fullstackandfullstack-tanstack: simplifiedsrc/middleware.ts; README line updated.solid-v2template:filesystem-routing0.4.0 → 0.4.2, lockfiles updated, andfile-routes.d.tsregenerated (0.4.2 emits the narrowerPick<...>ref types; dev rewrites the file anyway).No change needed in
filesystem-routingor@solidjs/vite-plugin.Verified
AsyncLocalStorage#getStore()returnundefined(as on StackBlitz): old template → 500 with this message; new template → 200 on/api/users./api/users→ 200 infullstackandfullstack-tanstack;fullstackproduction build +node dist/server/node.js→ 200.tsc --noEmitclean in both fullstack templates;fullstackvitest 11/11 passing;vite buildpasses in every template whose types were regenerated.Generated by Claude Code