Skip to content

Adopt ADR 0005 — route files export only Route; each route is a colocated folder #2

Description

@denkasyanov

Proposal to pull the route-component-colocation convention we shipped in muxa-io into stack. Decide accept/refuse while working in this repo — this issue just records the context.

What it is

A route file exports only Route. Each route becomes its own directory colocating route.tsx + -components/<name>.tsx + <feature>.test.tsx (route-only hooks in -hooks/, per ADR 0002). This restores TanStack Start's automatic code-splitting, which a named component export silently defeats — the route's render code stays in the eager route bundle and the dev server logs a code-split warning per route.

Why it matters for stack specifically

Stack already carries generalized ADR 0002 + 0003, but its placeholder routes currently demonstrate the exact anti-pattern 0005 fixes:

  • apps/web/src/routes/_app.home.tsx and apps/web/src/routes/index.tsx each set component: Home / component: Landing and export function Home() / export function Landing() — the named export exists only so home.test.tsx can import the component. That defeats code-splitting.

So a template that ships these teaches the anti-pattern by example.

Where it was done (muxa-io)

Rough scope if accepted

  • Add generalized docs/adr/0005-route-component-colocation.md (strip muxa-specific route names — Home/Backlog/Library/VideoDetail//v/$id).
  • Append the "Update (ADR 0005)" note to docs/adr/0002.
  • Refactor the 2 placeholder routes to the colocated layout: _app.home.tsx_app/home/{route.tsx (exports only Route), -components/home.tsx, home.test.tsx}; keep landing's index.tsx flat with -components/landing.tsx.
  • vite.config.ts: tanstackStart({ router: { routeFileIgnorePattern: ".*\\.test\\.tsx$" } }) to keep colocated *.test.tsx out of the route tree.
  • Regenerate routeTree.gen.ts.

Stack has only 2 real routes, so the code change is small.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions