-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
Description
Which project does this relate to?
Start
Describe the bug
When global middleware is registered per the instructions in https://tanstack.com/start/latest/docs/framework/react/middleware#global-request-middleware and referenced by server function, it ends up being executed multiple times.
Your Example Website or App
https://codesandbox.io/p/devbox/elated-ioana-8mjsp4
Steps to Reproduce the Bug or Issue
- Add a middleware function to the request middleware in
start.ts:
export const loggingMiddleware = createMiddleware().server(async ({ next }) => {
const request = getRequest();
console.log("request", request.url, crypto.randomUUID());
return next();
});
export const startInstance = createStart(() => {
return {
requestMiddleware: [loggingMiddleware],
};
});
- reference that middleware in a serverfn:
export const serverFn = createServerFn()
.middleware([loggingMiddleware])
.handler(async () => {
return { foo: "bar" };
});
- Call that serverfn in a beforeLoad context and fully reload the page
- Notice that three requests are logged with the same request url
Expected behavior
I expect a single log per request url
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.132.7
Additional context
No response
wand3r