Which project does this relate to?
Start
Describe the bug
When a middleware is using a server function that's placed in a different file, using said middleware in a different server function will cause the following error:
Server function info not found for [ID]
It's working fine when the server function is defined in the same file as the middleware
Your Example Website or App
Steps to Reproduce the Bug or Issue
- Add server function in a new file (i.e.
./server-fns/get-foo-bar.ts)
import { createServerFn } from "@tanstack/react-start";
export const getFooBar = createServerFn({ method: "GET" }).handler(
async () => {
return { foo: "bar" };
},
);
- Use this server function in a middleware that's stored in a separate file (i.e.
./middlewares/foo-bar-middleware)
import { createMiddleware } from "@tanstack/react-start";
import { getFooBar } from "#/server-fns/get-foo-bar";
export const fooBarMiddleware = createMiddleware({ type: "function" }).server(
async ({ next }) => {
const context = await getFooBar();
return next({ context });
},
);
- Use the middleware in a server function that's used within a route (i.e.
./routes/index.tsx)
import { createFileRoute } from "@tanstack/react-router";
import { fooBarMiddleware } from "#/middleware/foo-bar-middleware";
import { createServerFn } from "@tanstack/react-start";
const getFooBar = createServerFn({ method: "GET" })
.middleware([fooBarMiddleware])
.handler(async ({ context }) => {
console.log(context);
return context.foo;
});
export const Route = createFileRoute("/broken")({
component: RouteComponent,
loader: async () => {
const foo = await getFooBar();
return { foo };
},
});
function RouteComponent() {
const foo = Route.useLoaderData({
select: (ctx) => ctx.foo,
});
return <h1>{foo}</h1>;
}
- Start the development server and visit the route
- See that the page is working as expected
- Build the application
- Start the production server and visit the same page
- See that the page is broken and the following error is shown:
Server function info not found for [ID]
Expected behavior
As a user, I expected that this would work and that no error was thrown. However, this results in an production breaking exception
Screenshots or Videos
Platform
- Router / Start Version: 1.168.22
- OS: Linux
- Browser: Zen (Firefox based)
- Browser Version: 1.19.8b (Firefox 149.0.2) (64-bit)
- Bundler: Vite
- Bundler Version: 8.0.8
Additional context
No response
Which project does this relate to?
Start
Describe the bug
When a middleware is using a server function that's placed in a different file, using said middleware in a different server function will cause the following error:
It's working fine when the server function is defined in the same file as the middleware
Your Example Website or App
Steps to Reproduce the Bug or Issue
./server-fns/get-foo-bar.ts)./middlewares/foo-bar-middleware)./routes/index.tsx)Expected behavior
As a user, I expected that this would work and that no error was thrown. However, this results in an production breaking exception
Screenshots or Videos
Platform
Additional context
No response