Skip to content
Source
Sign inSign up
TanStack/cli

fix(create): use shared router factory in router-only apps #481

Mergedgs0428(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/481/headmerged by tannerlinsley

React and Solid router-only apps now call the shared getRouter() factory, so router customizations apply and the Register declaration stays in one place.

Adding Query to either framework wraps the router with its browser Query provider and uses the same query client as router context. React router-only output no longer imports the Start SSR integration. The add command also lets pnpm update the lockfile after intentionally changing dependencies, including in CI.

Validation:

  • Repository build and 456 unit tests passed.
  • Four affected browser cases generated apps outside the monorepo, installed dependencies, built and type-checked both frameworks, and verified custom router settings and Query results.
  • The normal pre-commit build, unit and eight blocking browser checks passed.

Fixes #480 and #522.

Summary by CodeRabbit

  • New Features
    • Router-only React and Solid apps now use consistent router setup, with router type support available in the router configuration.
    • Adding TanStack Query to a router-only app now provides query access in the browser without requiring server-rendering integration.
  • Bug Fixes
    • Adding dependencies to an existing app with pnpm can now update the lockfile in CI instead of failing because of frozen-lockfile settings.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 4916c573-1952-4e8f-ab16-737de35aadda
      Commits

      Reviewing files that changed from the base of the PR and between e4b8ef506bcdfbcdf75f2bc9d06143d68a4dfe6a and b99bf948a5e652829e79f59cea5caf39f3a3393f.

      Files selected for processing: 9
      • .changeset/shared-router-factory.md
      • packages/cli/tests-e2e/helpers.ts
      • packages/cli/tests-e2e/shared-router-factory.spec.ts
      • packages/create/src/add-to-app.ts
      • packages/create/src/frameworks/react/project/base/src/router.tsx.ejs
      • packages/create/src/frameworks/solid/project/base/src/router.tsx.ejs
      • packages/create/src/package-manager.ts
      • packages/create/tests/framework-template.test.ts
      • packages/create/tests/package-manager.test.ts
      Files skipped from review as they are similar to previous changes: 1
      • .changeset/shared-router-factory.md

      Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

      Walkthrough

      React and Solid router-only templates now initialize through getRouter() and configure Query providers without SSR query integration. Tests cover generated templates and router-only app behavior. The add-to-app installation path can update pnpm lockfiles when it installs dependencies.

      Changes: Router-only templates and Query

      Layer / File(s)Summary
      Shared router initialization
      packages/create/src/frameworks/react/project/base/src/main.tsx.ejs, packages/create/src/frameworks/solid/project/base/src/main.tsx.ejs
      Both templates call getRouter() instead of constructing the router inline. They remove the local router type augmentation.
      Router-only Query providers
      packages/create/src/frameworks/react/project/base/src/router.tsx.ejs, packages/create/src/frameworks/solid/project/base/src/router.tsx.ejs
      React uses QueryClientProvider and skips SSR query integration in router-only mode. Solid passes Query context into the router and provides context.queryClient in router-only mode.
      Generated app verification
      packages/create/tests/framework-template.test.ts, packages/cli/tests-e2e/shared-router-factory.spec.ts, packages/cli/tests-e2e/helpers.ts, .changeset/shared-router-factory.md
      Template tests check generated router and Query output. End-to-end tests check not-found rendering and Query routes in React and Solid. The fixture helper passes --forced to the add command.

      pnpm lockfile updates

      Layer / File(s)Summary
      Dependency installation option
      packages/create/src/add-to-app.ts, packages/create/src/package-manager.ts, packages/create/tests/package-manager.test.ts, .changeset/shared-router-factory.md
      The add-to-app flow requests lockfile updates. With the option enabled, pnpm installs without a package use --no-frozen-lockfile; npm install arguments remain unchanged. Tests cover these cases.

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

      Change: Bug fix

      Suggested reviewers: tannerlinsley, brenelz, symind

      Merge Risk: Minimal · up to b99bf

      Router-only apps use the shared factory and Query providers. No merge-blocking issue was identified.

      Pre-merge checks: Passed 3 · Failed 2
      Failed Failed checks: 2 warnings
      Check nameStatusExplanationResolution
      Out of Scope Changes checkWarningThe supplied active linked issue is [#480]. The PR also changes Query provider generation, SSR Query imports, package-manager lockfile behavior, the add-on test helper, and related tests and release n…Keep this PR limited to [#480] by removing the unrelated Query, lockfile, add-on helper, and associated production and test changes, or provide the active linked issue requirements that explicitly cover those changes.
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Description CheckPassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title checkPassedThe title clearly and concisely describes the main change: using the shared router factory in router-only applications.
      Linked Issues checkPassedIssue [#480] requires router-only React and Solid main.tsx templates to import and call getRouter() from router.tsx. The whole-PR diff shows both templates make this change and remove inline rou…
      Full details: Linked Issues check

      Explanation

      Issue [#480] requires router-only React and Solid main.tsx templates to import and call getRouter() from router.tsx. The whole-PR diff shows both templates make this change and remove inline router creation. The templates also remove the duplicate Register declarations from main.tsx. router.tsx.ejs keeps the factory and the single Register declaration. Template tests cover both frameworks and the end-to-end tests verify factory configuration at runtime.

      Full details: Out of Scope Changes check

      Explanation

      The supplied active linked issue is [#480]. The PR also changes Query provider generation, SSR Query imports, package-manager lockfile behavior, the add-on test helper, and related tests and release notes. These changes have no concrete connection to #480, which only requires the shared router factory and the single Register declaration. The PR description mentions #522, but no linked-issue requirements for #522 are supplied for this assessment.

      Resolution

      Keep this PR limited to [#480] by removing the unrelated Query, lockfile, add-on helper, and associated production and test changes, or provide the active linked issue requirements that explicitly cover those changes.

      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 with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 6 files. (3 skipped: 3 unsupported.)

      Resolution

      Write docstrings for the functions missing them to satisfy the coverage threshold.

      Finishing Touches
      Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Warning

      Some tools did not complete. Review the errors below.

      ESLint

      If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

      packages/cli/tests-e2e/helpers.ts

      Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser. The file was not found in any of the provided project(s): packages/cli/tests-e2e/helpers.ts

      packages/cli/tests-e2e/shared-router-factory.spec.ts

      Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser. The file was not found in any of the provided project(s): packages/cli/tests-e2e/shared-router-factory.spec.ts

      packages/create/tests/framework-template.test.ts

      Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser. The file was not found in any of the provided project(s): packages/create/tests/framework-template.test.ts

      • 1 others

      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
    2. 🧹 Nitpick comments (1)
      packages/create/tests/framework-template.test.ts (1)

      73-99: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

      Assert the RouterProvider package import too.

      These expectations would still pass if main.tsx imported RouterProvider from the wrong framework package. Adding that assertion closes the cross-framework contract gap.

      Suggested test addition
             expect(main).toContain(getRouterImport)
      +      expect(main).toContain(
      +        `import { RouterProvider } from '${routerPackage}'`,
      +      )
             expect(main).toContain('const router = getRouter()')
      🤖 Prompt for AI Agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      In `@packages/create/tests/framework-template.test.ts` around lines 73 - 99, The
      router-only entry test in framework-template.test.ts is missing an assertion for
      the RouterProvider import source, so it could still pass with the wrong
      framework package. Update the renderRouterOnlyEntries expectations in the shared
      router factory test to also verify the main entry imports RouterProvider from
      the correct framework-specific package, alongside the existing getRouter,
      createRouter, and declare module checks.
      🤖 Prompt for all review comments with AI agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      Nitpick comments:
      In `@packages/create/tests/framework-template.test.ts`:
      - Around line 73-99: The router-only entry test in framework-template.test.ts is
      missing an assertion for the RouterProvider import source, so it could still
      pass with the wrong framework package. Update the renderRouterOnlyEntries
      expectations in the shared router factory test to also verify the main entry
      imports RouterProvider from the correct framework-specific package, alongside
      the existing getRouter, createRouter, and declare module checks.

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: ffe9213f-35bd-4052-9e3d-b73028fe98b1

      📥 Commits

      Reviewing files that changed from the base of the PR and between 12c31dfb429ec057af9ddc5f85f492b0b0b22979 and 58370320bc6747fd91f5c25b09dd79e5166545e8.

      📒 Files selected for processing (3)
      • packages/create/src/frameworks/react/project/base/src/main.tsx.ejs
      • packages/create/src/frameworks/solid/project/base/src/main.tsx.ejs
      • packages/create/tests/framework-template.test.ts
    3. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: b99bf948a5e652829e79f59cea5caf39f3a3393f

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 7 packages
      NameType
      @tanstack/createPatch
      create-start-appPatch
      create-tanstack-appPatch
      create-tanstackPatch
      create-tsrouter-appPatch
      @tanstack/create-startPatch
      @tanstack/cliPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    4. tannerlinsleycommented

      The Query repair is now pushed for both frameworks. Generated-app checks and the normal local gates passed at b99bf948, and this updated head is waiting for CI and review.

    5. tannerlinsley merged thisfcff1bf

    6. tannerlinsley closed this

Sign in to join this conversation.