Skip to content
Source
Sign inSign up
TanStack/router

fix(router-generator): scaffold plain TypeScript routes without JSX #8481

Opennathan-logan(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8481/headopened

🎯 Changes

Fixes #8480.

Creating an empty .ts file within the routes folder broke all route generation with the error: SyntaxError: Missing semicolon. (8:19).

The generator scaffolds empty route files with the target's built in template, which for React & Solid includes a JSX hello world component. This then fails to parse for plain TypeScript files due to Babel's jsx plugin being omitted for .ts filenames. This throws an error before the file is written, so the route file remains empty, and the route tree isn't generated until the file is deleted or populated by hand.

This change opts to scaffold plain TypeScript files with no component instead. A .ts route file is almost always a server route, and a component cannot be added without renaming to .tsx anyway:

import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/api/foo')({})
  • Added an opts argument to template() and the root route's tsrImports(), which includes allowJsx, when this is false the JSX is dropped, and also the root route's Outlet import as it would be unused.
  • Vue and user configured custom scaffolding have been left as is.
  • Added typescript-server-route test, housing an empty foo.ts and foobar.lazy.ts alongside some .tsx routes. This test fails on main with the semicolon error above.
  • Added typescript-root-route test, has an empty __root.ts just to cover the empty root case.
  • I followed the tests.test-d.ts convention from the nested tests, as I had some TypeScript errors due to it not type-checking against the generated route tree.
  • Copied across the isPlainTypeScriptFile util from router-utils rather than exporting it.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed route generation failures caused by empty .ts route files. Generated plain TypeScript routes now use JSX-free scaffolding, while JSX-capable file extensions retain JSX templates.
    1. Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Repository: TanStack/router/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: ec3ac263-68b7-4416-9ec7-6355519b1f76

      📥 Commits

      Reviewing files that changed from the base of the PR and between fe7f1fd0e6ef73c3f341dd2338b406749538a85d and 4cdb33e62677fae9e3ed97df0f00f7b7a1df65bd.

      📒 Files selected for processing (19)
      • .changeset/router-generator-ts-scaffolding.md
      • packages/router-generator/src/generator.ts
      • packages/router-generator/src/template.ts
      • packages/router-generator/src/utils.ts
      • packages/router-generator/tests/generator.test.ts
      • packages/router-generator/tests/generator/typescript-root-route/routeTree.snapshot.ts
      • packages/router-generator/tests/generator/typescript-root-route/routes/__root.ts
      • packages/router-generator/tests/generator/typescript-root-route/snapshots/__root.ts
      • packages/router-generator/tests/generator/typescript-root-route/tests.test-d.ts
      • packages/router-generator/tests/generator/typescript-server-route/routeTree.snapshot.ts
      • packages/router-generator/tests/generator/typescript-server-route/routes/__root.tsx
      • packages/router-generator/tests/generator/typescript-server-route/routes/api/bar.tsx
      • packages/router-generator/tests/generator/typescript-server-route/routes/api/foo.ts
      • packages/router-generator/tests/generator/typescript-server-route/routes/api/foobar.lazy.ts
      • packages/router-generator/tests/generator/typescript-server-route/routes/foo.lazy.tsx
      • packages/router-generator/tests/generator/typescript-server-route/routes/index.tsx
      • packages/router-generator/tests/generator/typescript-server-route/snapshots/api/foo.ts
      • packages/router-generator/tests/generator/typescript-server-route/snapshots/api/foobar.lazy.ts
      • packages/router-generator/tests/generator/typescript-server-route/tests.test-d.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      Route generation now scaffolds plain .ts, .cts, and .mts route files without JSX. React and Solid templates retain JSX for other extensions. New generator tests cover TypeScript route fixtures, generated snapshots, and route tree typechecks.

      Changes

      Plain TypeScript route scaffolding

      Layer / File(s)Summary
      Extension-aware route templates
      packages/router-generator/src/utils.ts, packages/router-generator/src/template.ts
      The generator adds a helper to identify plain TypeScript file extensions. React and Solid templates use a JSX-free route template when JSX is not allowed.
      Generator template selection
      packages/router-generator/src/generator.ts
      Root, normal, and lazy route scaffolding pass an allowJsx value derived from the route file path.
      TypeScript route fixtures and validation
      packages/router-generator/tests/generator.test.ts, packages/router-generator/tests/generator/typescript-root-route/*, packages/router-generator/tests/generator/typescript-server-route/*, .changeset/router-generator-ts-scaffolding.md
      Tests add TypeScript root and server-route fixtures, generated snapshots, and router typechecks. The changeset records a patch release.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Merge Risk: ⚪ Minimal · up to 4cdb3

      Plain TypeScript routes can be scaffolded without JSX, and component-free root routes still render their children. No merge-blocking issue remains.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 18 files. (1 skipped: …Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedIssue [#8480] requires valid TypeScript scaffolding for empty .ts routes. The change adds isPlainTypeScriptFile and passes the resulting JSX mode to React and Solid route templates. When JSX is di…
      Out of Scope Changes check✅ PassedThe changes stay within issue [#8480]. The helper, template options, JSX gating, changeset, generator fixtures, snapshots, and type-checking tests all support plain TypeScript route scaffolding or ver…
      Title check✅ PassedThe title clearly and concisely describes the main change: plain TypeScript routes are scaffolded without JSX.
      Description check✅ PassedThe description explains the problem, the fix, the affected templates, the added tests, and the release impact. It includes all required template sections and completes the checklist.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 18 files. (1 skipped: 1 unsupported.)

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. View your CI Pipeline Execution ↗ for commit 4cdb33e62677fae9e3ed97df0f00f7b7a1df65bd

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...❌ Failed19m 21sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded2m 10sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-09-23 16:15:54 UTC

    3. More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/@tanstack/arktype-adapter@8481

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8481

      @tanstack/eslint-plugin-start

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8481

      @tanstack/history

      npm i https://pkg.pr.new/@tanstack/history@8481

      @tanstack/nitro-v2-vite-plugin

      npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8481

      @tanstack/react-router

      npm i https://pkg.pr.new/@tanstack/react-router@8481

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/@tanstack/react-router-devtools@8481

      @tanstack/react-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8481

      @tanstack/react-start

      npm i https://pkg.pr.new/@tanstack/react-start@8481

      @tanstack/react-start-client

      npm i https://pkg.pr.new/@tanstack/react-start-client@8481

      @tanstack/react-start-rsc

      npm i https://pkg.pr.new/@tanstack/react-start-rsc@8481

      @tanstack/react-start-server

      npm i https://pkg.pr.new/@tanstack/react-start-server@8481

      @tanstack/router-cli

      npm i https://pkg.pr.new/@tanstack/router-cli@8481

      @tanstack/router-core

      npm i https://pkg.pr.new/@tanstack/router-core@8481

      @tanstack/router-devtools

      npm i https://pkg.pr.new/@tanstack/router-devtools@8481

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/@tanstack/router-devtools-core@8481

      @tanstack/router-generator

      npm i https://pkg.pr.new/@tanstack/router-generator@8481

      @tanstack/router-plugin

      npm i https://pkg.pr.new/@tanstack/router-plugin@8481

      @tanstack/router-ssr-query-core

      npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8481

      @tanstack/router-utils

      npm i https://pkg.pr.new/@tanstack/router-utils@8481

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8481

      @tanstack/solid-router

      npm i https://pkg.pr.new/@tanstack/solid-router@8481

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8481

      @tanstack/solid-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8481

      @tanstack/solid-start

      npm i https://pkg.pr.new/@tanstack/solid-start@8481

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/@tanstack/solid-start-client@8481

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/@tanstack/solid-start-server@8481

      @tanstack/start-client-core

      npm i https://pkg.pr.new/@tanstack/start-client-core@8481

      @tanstack/start-fn-stubs

      npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8481

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/@tanstack/start-plugin-core@8481

      @tanstack/start-server-core

      npm i https://pkg.pr.new/@tanstack/start-server-core@8481

      @tanstack/start-static-server-functions

      npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8481

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/@tanstack/start-storage-context@8481

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/@tanstack/valibot-adapter@8481

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8481

      @tanstack/vue-router

      npm i https://pkg.pr.new/@tanstack/vue-router@8481

      @tanstack/vue-router-devtools

      npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8481

      @tanstack/vue-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8481

      @tanstack/vue-start

      npm i https://pkg.pr.new/@tanstack/vue-start@8481

      @tanstack/vue-start-client

      npm i https://pkg.pr.new/@tanstack/vue-start-client@8481

      @tanstack/vue-start-server

      npm i https://pkg.pr.new/@tanstack/vue-start-server@8481

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/@tanstack/zod-adapter@8481

      commit: 4cdb33e

    4. Merging this PR will not alter performance

      ✅ 189 untouched benchmarks ⏩ 3 skipped benchmarks1


      Comparing nathan-logan:fix/router-generator-plain-ts-route-scaffolding (4cdb33e) with main (fe7f1fd) Open in CodSpeed

      Footnotes

      1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

    5. Nx Cloud has identified a flaky task in your failed CI:

      🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

      Nx Cloud View detailed reasoning in Nx Cloud ↗


      🎓 Learn more about Self-Healing CI on [nx.dev](https://nx.dev/docs/features/ci-features/self-healing-ci?utm_source=pull-request&utm_medium=comment)

Sign in to join this conversation.