TanStack Start 1.0: I ported a Next.js page and the compiler caught my redirect

By Esteban Trillo7 min readReactNext.jsTypeScriptCloudflare

Piwi carries the issues page out of the Next.js box. In the Start box, every line that crosses to the server gets a tag with its name on it.
Piwi carries the issues page out of the Next.js box. In the Start box, every line that crosses to the server gets a tag with its name on it.

The first thing that broke when I ported a Next.js page to TanStack Start was a redirect.

src/routes/index.tsx
throw redirect({ to: "/issues" });
tsc --noEmit
src/routes/index.tsx(5,20): error TS2345: Argument of type '{ to: "/issues"; }'
is not assignable to parameter of type 'RedirectOptions<...>'.
Property 'search' is missing in type '{ to: "/issues"; }'

The router knew that /issues takes a status and a sort, and that I hadn’t passed either. In Next.js that redirect is a string, and the page sorts out whatever shows up.

That error is most of what TanStack Start is selling. Start 1.0 went stable on October 13, and the question I keep hearing is whether it’s worth leaving Next for. So I took one realistic page, ported it, and wrote down everything that moved.

The page

It’s a small issue tracker on Next.js 16.4.3: a list you filter and sort through the URL, a form that adds an issue, a header with counts, and a cookie session that gates all of it. The data sits in an in-memory array on purpose, because this post is about the framework, not the database.

gh
$ gh repo view devtrillo/nextjs-to-tanstack-start --branch tanstack-start▋
devtrillo/nextjs-to-tanstack-starttanstack-start

The issue tracker before and after: the nextjs tag is the App Router version, the tanstack-start tag is the port running on Cloudflare Workers. PR #1 has every change in one diff.

$ git clone -b tanstack-start https://github.com/devtrillo/nextjs-to-tanstack-start.git
View this repository on GitHub: https://github.com/devtrillo/nextjs-to-tanstack-start/tree/tanstack-start↗

Here’s the Next version of the page. It’s an async server component, which is the App Router default:

app/issues/page.tsx (Next.js)
export default async function IssuesPage({
searchParams,
}: {
searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
const user = await requireUser();
const search = issueSearch.parse(await searchParams);
const issues = listIssues(search);
return (
<main>
<p>Signed in as {user}</p>
<Stats />
<Filters {...search} />
<NewIssueForm />
<ul>{/* issues */}</ul>
</main>
);
}

It’s short and it works. But look at what it leaves to convention: searchParams is a bag of strings until I parse it, requireUser() has to be called in every page and every action that needs it, and nothing in the file says which lines run on the server. All of it does, because it’s an app/ file without 'use client' at the top.

I’m using @tanstack/react-start 1.169.4. That’s the 1.0 release, because there’s no 1.0.0 package. Start has been on the router’s version line for a while. It also needs Vite 8.

Loaders run on both sides

In Next, the page component is where data gets fetched. In Start, a route has a loader, and the loader is isomorphic: it runs on the server for the first request and in the browser on every client navigation after that. So it can’t touch the database directly. It calls a server function, and the server function is the only thing that runs on the server.

src/routes/_authed/issues.tsx
export const Route = createFileRoute("/_authed/issues")({
validateSearch: issueSearch,
loaderDeps: ({ search: { status, sort } }) => ({ status, sort }),
loader: async ({ deps }) => {
const [issues, { Stats }] = await Promise.all([
getIssues({ data: deps }),
getStats(),
]);
return { issues, Stats };
},
component: IssuesPage,
});
src/server/issues.ts
export const getIssues = createServerFn()
.middleware([authMiddleware])
.validator(issueSearch)
.handler(({ data }) => listIssues(data));

That’s more ceremony than Next, and I didn’t like it at first. Then it caught a real mistake. My first version imported the Zod schema from the same file that held the in-memory issues. The route runs in the browser, so the seed data would have ended up in the client bundle. In Next, a server component importing that file is fine, and a client component importing it is a quiet leak. In Start, the question “does this file run in the browser?” has one answer for every route file: yes. So I moved the schemas into their own module and grepped the client build to confirm the data was gone.

Search params get a type

validateSearch takes the Zod 4 schema directly, with no adapter, and from then on the URL is typed everywhere. Here’s the filter dropdown before:

app/issues/filters.tsx (Next.js)
function set(key: string, value: string) {
const next = new URLSearchParams(params);
next.set(key, value);
router.push(`${pathname}?${next}`);
}

And after:

src/routes/_authed/issues.tsx
const { status, sort } = Route.useSearch();
const navigate = Route.useNavigate();
navigate({
search: (prev) => ({
...prev,
sort: issueSearch.shape.sort.parse(e.target.value),
}),
});

In the Next version I can write set('sotr', 'oldset') and find out in the browser. In Start that’s a compile error, and so is a redirect or <Link> to /issues that forgets the params. That’s the error at the top of this post. I fixed it by giving the schema defaults, .default('all').catch('all'), so both params are optional and a malformed URL falls back instead of throwing.

There’s one visible side effect. Start writes the defaults into the URL, so /issues becomes /issues?status=all&sort=newest after a 307. If you want clean URLs, the router has search middleware to strip defaults. I left it alone.

A mutation is a function you call

The Next form used a Server Action with useActionState and revalidatePath('/issues'). In Start it’s a POST server function and a router invalidate:

src/server/issues.ts
export const createIssue = createServerFn({ method: "POST" })
.middleware([authMiddleware])
.validator(newIssue)
.handler(({ data, context }) => {
insertIssue(data.title, context.user);
});
NewIssueForm
const create = useServerFn(createIssue);
// in onSubmit:
await create({ data: { title } });
await router.invalidate(); // re-runs the loader: list and stats

router.invalidate() is the replacement for revalidatePath, but it’s narrower. It marks the router’s cached loader data stale and re-runs the active route’s loaders, and that’s it. There’s no server-side cache to purge, because Start doesn’t keep one.

This is where I lost something. The Next form posts without JavaScript, because Server Actions are wired into <form action>. My Start form is an onSubmit handler, so it needs JavaScript. The Next.js migration guide says it directly: don’t treat createServerFn as a drop-in for the form Action protocol. If no-JS forms matter to you, it points at FormData server-function URLs or server routes, and that’s more work than Next makes it.

Auth becomes middleware with a type

In Next I had a requireUser() helper that read cookies() and called redirect('/login'), and I had to remember to call it in the page and in the action. In Start the check moves into middleware, and the middleware hands the user to the handler:

src/server/auth.ts
export const authMiddleware = createMiddleware({ type: "function" }).server(
({ next }) => {
const user = readUser();
if (!user) throw redirect({ to: "/login" });
return next({ context: { user } });
},
);

Any server function that lists authMiddleware gets context.user as a string, so you can’t forget the check and still get the user. That’s the context.user in createIssue above.

Routes are gated by a pathless _authed layout. Every file under src/routes/_authed/ goes through its beforeLoad:

src/routes/_authed.tsx
export const Route = createFileRoute("/_authed")({
beforeLoad: async () => {
const user = await getUser();
if (!user) throw redirect({ to: "/login" });
return { user };
},
component: Outlet,
});

The auth guide is careful to say beforeLoad “is not the security boundary for the data”. It only controls navigation. A server function is a public endpoint whether or not any route calls it, so the middleware on each one is the real check, and the layout just makes the redirect happen before the page renders.

One trap I found reading the middleware docs. If you add a src/start.ts to register global middleware, Start stops installing its CSRF protection for server functions, and you have to add createCsrfMiddleware() back yourself. I didn’t need a start.ts, so I didn’t make one.

Server components are opt-in

In Next, everything is a server component unless you say otherwise. In Start it’s the other way round. Routes render the normal way, SSR and then hydration, and you can control that per route with ssr: true, 'data-only' or false. A server component is something you ask for, one piece at a time.

The stats header is a good candidate: it’s read-only and has no interactivity. Here it is as a React Server Component:

src/server/stats.tsx
import { renderServerComponent } from "@tanstack/react-start/rsc";
function Stats() {
const stats = issueStats();
return (
<p className="stats">
<span>{stats.open} open</span>
<span>{stats["in-progress"]} in progress</span>
<span>{stats.closed} closed</span>
</p>
);
}
export const getStats = createServerFn()
.middleware([authMiddleware])
.handler(async () => ({ Stats: await renderServerComponent(<Stats />) }));

The loader returns Stats next to the issues, the page renders {Stats}, and router.invalidate() after a mutation fetches a fresh one. When I added an issue, the count went from 2 open to 3 without any extra code. It needs @vitejs/plugin-rsc and rsc: { enabled: true } on the Start plugin.

I’d be careful here, though. The server components guide says they’re experimental and “will remain so into early v1”. The 1.0 release is stable. Its RSC support isn’t.

Deploying to Cloudflare Workers

Start deploys to Workers through @cloudflare/vite-plugin, not a Nitro preset. The wrangler config points main at Start’s built-in entry:

wrangler.jsonc
{
"name": "nextjs-to-tanstack-start",
"compatibility_date": "2026-10-26",
"compatibility_flags": ["nodejs_compat"],
"main": "@tanstack/react-start/server-entry",
}

The Vite config looks like the official Cloudflare example, plus one option that no example has:

vite.config.ts
plugins: [
cloudflare({ viteEnvironment: { name: 'ssr', childEnvironments: ['rsc'] } }),
tanstackStart({ rsc: { enabled: true } }),
rsc(),
viteReact(),
],

Without childEnvironments: ['rsc'], vite build passes and every request to vite preview returns a 500:

vite preview, inside workerd
Error("No such module \"rsc/assets/@tanstack/router-core/ssr/client\".
imported from \"rsc/assets/session-svQ1Mhbw.js\"")
GET /issues 500 Internal Server Error (21ms)

The Cloudflare plugin builds one Worker from the ssr environment, and the RSC plugin adds a separate rsc environment that ends up outside it. childEnvironments puts it inside. The plugin’s API reference says the option exists for @vitejs/plugin-rsc, but none of the Start examples use RSC and Cloudflare together, so I only found it by trying. If you skip RSC, you don’t need it.

With that line in place, the whole page works in vite preview, which runs on workerd, Cloudflare’s runtime. That covers login, filters, the mutation and the server component refresh. wrangler deploy --dry-run puts the Worker at 343 KiB gzipped.

The verdict

The full port is one PR: 389 lines in and 174 out across 24 files, and most of the growth is the server functions and the route config. It’s more code than the Next version. I’d keep almost all of it.

Switch to Start if you care more about explicit server boundaries and type-safe URLs than you lean on Next’s ecosystem and Vercel’s integration. The port itself was mechanical. Page → route, action → server function, revalidatePath → invalidate, helper → middleware. The real change is how you think about where code runs. In Next, a file runs on the server because of where it sits and what’s missing from the top of it. In Start, it runs on the server because you wrapped it in createServerFn, and you can grep for that.

Stay on Next if your forms have to work without JavaScript, if server components are most of your app and not one header, or if your deploy story is “push to Vercel” and that’s fine. Start’s RSC is still experimental, and the forms story is honestly worse.

What sold me was the error at the top. A redirect with no params didn’t compile, because the router knew more about my URLs than I did. Next lets that ship. Start doesn’t.

Piwi hands a single letter to the user at a mailbox; a small note reads no noise.

Get the next one in your inbox

One email when a post goes out, with its sketch. Nothing in between, and one link to leave.

Sign in faster next time?

Add a passkey and skip the email link. Your fingerprint, face or device PIN is enough.