-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Which project does this relate to?
Start
Describe the bug
When using createStart({ requestMiddleware }) to register global request middleware, the pathname property passed to the middleware's server function is undefined at runtime, despite the TypeScript type RequestServerOptions declaring it as pathname: string.
Root Cause:
In packages/start-server-core/src/createStartHandler.ts, the two executeMiddleware calls for global request middleware do not include pathname in the initial context object:
- Server function path (L532-535):
{ request, context }— missingpathname - Page request path (L626-629):
{ request, context }— missingpathname
The route-level middleware execution in handleServerRoutes (L784-789) correctly passes pathname.
The url variable (new URL(request.url) via getNormalizedURL) is already available in scope, so the fix is simply adding pathname: url.pathname to both call sites.
Your Example Website or App
N/A (root cause is clearly visible in source code)
Steps to Reproduce the Bug or Issue
- Register a request middleware via
createStart():
const myMiddleware = createMiddleware({ type: 'request' }).server(
async ({ pathname, next }) => {
console.log(pathname) // → undefined (should be a string)
return next()
},
)
export const startInstance = createStart(() => ({
requestMiddleware: [myMiddleware] as const,
}))- Access any page or call any server function
pathnameisundefined
Expected behavior
pathname should be a string containing the request path (e.g., /api/users), as declared in the RequestServerOptions type.
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.159.4
- OS: macOS
- Browser: N/A (server-side)
- Browser Version: N/A
- Bundler: vite
- Bundler Version: N/A
Additional context
A fix PR will be submitted shortly.