Skip to content
Source
Sign inSign up
TanStack/router

docs(solid-router): authenticated-routes example #5825

Mergedbirkskyum(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/5825/headmerged by birkskyum(GitHub profile, opens in a new tab)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a complete Solid.js authenticated routing example project showcasing login/logout flows, protected routes with authentication guards, dashboard navigation, and invoice management powered by TanStack Router.
  • Documentation

    • Added example project README with setup and run instructions.
    1. Walkthrough

      Adds a complete authenticated routes example for Solid.js using TanStack Router, featuring authentication context, protected routes with beforeLoad guards, data loading, login/redirect flows, and Tailwind CSS styling.

      Changes

      Cohort / File(s)Summary
      Project Configuration
      .gitignore, tsconfig.json, vite.config.js, postcss.config.mjs, package.json
      Set up project metadata, build tooling (Vite with TanStack Router plugin and vite-plugin-solid), TypeScript strict mode, PostCSS for Tailwind, and standard ignores (node_modules, dist, .DS_Store).
      VS Code & Documentation
      .vscode/settings.json, README.md, index.html
      Configure workspace to exclude generated routeTree.gen.ts from watchers and mark as readonly; add setup instructions and HTML entry point for Vite app.
      Authentication & App Bootstrap
      src/auth.tsx, src/main.tsx, src/utils.ts
      Implement AuthContext with login/logout backed by localStorage; set up app root with AuthProvider, router creation, context injection, and a reusable sleep utility.
      Data Layer
      src/posts.tsx
      Provide cached invoice fetching with configurable loader delay; exports fetchInvoices() and fetchInvoiceById(id) functions.
      Routes
      src/routes/__root.tsx, src/routes/index.tsx, src/routes/login.tsx, src/routes/_auth.tsx, src/routes/_auth.dashboard.tsx, src/routes/_auth.invoices.tsx, src/routes/_auth.invoices.index.tsx, src/routes/_auth.invoices.$invoiceId.tsx, src/routeTree.gen.ts
      Define root route with devtools, public home page, login route with redirect validation and beforeLoad auth check, protected _auth layout with logout, dashboard, invoices list with grid layout, invoices index placeholder, and invoice detail page with loader. Generated routeTree wires all routes into typed hierarchy.
      Styling
      src/styles.css
      Apply Tailwind CSS directives, set base layer border colors via CSS variables, and configure light/dark theme colors.

      Sequence Diagram

      sequenceDiagram
          participant User
          participant App
          participant Router
          participant Auth
          participant Storage as localStorage
          
          rect rgb(200, 220, 240)
              Note over User,Storage: Initial App Load
              User->>App: Open /dashboard
              App->>Auth: useAuth() → isAuthenticated?
              Auth->>Storage: Check 'tanstack.auth.user'
              Storage-->>Auth: null (not logged in)
              Auth-->>App: false
          end
          
          rect rgb(220, 200, 240)
              Note over User,Router: beforeLoad Guard
              App->>Router: beforeLoad redirect check
              Router->>Router: isAuthenticated === false
              Router->>User: Redirect to /login?redirect=/dashboard
          end
          
          rect rgb(200, 240, 220)
              Note over User,Storage: Login Flow
              User->>App: Submit login form (username)
              App->>Auth: login('alice')
              Auth->>Auth: Simulate delay
              Auth->>Storage: setStoredUser('alice')
              Storage-->>Auth: ✓
              Auth-->>App: Promise resolved
              App->>Router: Invalidate & navigate to /dashboard
          end
          
          rect rgb(240, 220, 200)
              Note over User,Storage: Protected Route Access
              Router->>Auth: beforeLoad checks isAuthenticated
              Auth->>Storage: getStoredUser()
              Storage-->>Auth: 'alice'
              Auth-->>Router: true ✓
              Router->>App: Render /_auth/dashboard
              App-->>User: Show "Welcome, alice!"
          end

      Estimated code review effort

      🎯 3 (Moderate) | ⏱️ ~20 minutes

      • Focus areas:
        • src/auth.tsx — AuthContext implementation, storage persistence, and login/logout logic
        • src/routes/_auth.tsx — beforeLoad guard, logout handler, and navigation flow
        • src/routes/_auth.invoices.$invoiceId.tsx — loader function and error handling for invoice fetching
        • src/routeTree.gen.ts — verify generated route tree structure, parent-child relationships, and type exports
        • Route file naming patterns — ensure file-based routing conventions are consistent across _auth., $invoiceId dynamic segments
      • TanStack/router#5633 — Modifies Solid route generation and routeTree.gen.ts structure, directly related to this PR's generated artifacts.
      • TanStack/router#5556 — Adds another Solid.js example project with similar routeTree.gen.ts and router setup patterns.
      • TanStack/router#5491 — Changes router-generator output for route IDs and path normalization, affecting generated routeTree shape.

      Suggested labels

      documentation, package: solid-router

      Suggested reviewers

      • birkskyum
      • brenelz

      Poem

      🐰 A rabbit hops through routes so neat, Auth guards protect each protected street, Invoices load with Solid's grace, Login redirects find their place, TanStack Router guides the way, Authenticated routes—hooray, hooray! 🎉

      Pre-merge checks and finishing touches

      ❌ Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.You can run @coderabbitai generate docstrings to improve docstring coverage.
      ✅ Passed checks (2 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title 'docs(solid-router): authenticated-routes example' accurately describes the changeset, which adds a complete authenticated-routes example for Solid Router with authentication context, protected routes, and related configuration files.
      ✨ Finishing touches
      • 📝 Generate docstrings
        🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Post copyable unit tests in a comment
      • Commit unit tests in branch `docs(solid-router)--authenticated-routes-example`

      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 and usage tips.
    2. View your CI Pipeline Execution ↗ for commit 5feb7e266f3c8c50fc17c14b61653cfc71cc4b57

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded49sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded3sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-11-11 23:50:08 UTC

    3. More templates

      @tanstack/arktype-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5825

      @tanstack/directive-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5825

      @tanstack/eslint-plugin-router

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

      @tanstack/history

      npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5825

      @tanstack/nitro-v2-vite-plugin

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

      @tanstack/react-router

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

      @tanstack/react-router-devtools

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

      @tanstack/react-router-ssr-query

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

      @tanstack/react-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5825

      @tanstack/react-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5825

      @tanstack/react-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5825

      @tanstack/router-cli

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

      @tanstack/router-core

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

      @tanstack/router-devtools

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

      @tanstack/router-devtools-core

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

      @tanstack/router-generator

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

      @tanstack/router-plugin

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

      @tanstack/router-ssr-query-core

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

      @tanstack/router-utils

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

      @tanstack/router-vite-plugin

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

      @tanstack/server-functions-plugin

      npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5825

      @tanstack/solid-router

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

      @tanstack/solid-router-devtools

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

      @tanstack/solid-router-ssr-query

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

      @tanstack/solid-start

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5825

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5825

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5825

      @tanstack/start-client-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5825

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5825

      @tanstack/start-server-core

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5825

      @tanstack/start-static-server-functions

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

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5825

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5825

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5825

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5825

      commit: 5feb7e2

    4. Actionable comments posted: 4

      🧹 Nitpick comments (4)
      examples/solid/authenticated-routes/README.md (1)

      1-1: Consider a more descriptive heading.

      The heading "# Example" is generic. Updating it to "# Authenticated Routes Example" or similar would make the purpose of the example immediately clear to readers, aligning with the directory name and example's functionality.

      -# Example
      +# Authenticated Routes Example
      examples/solid/authenticated-routes/src/posts.tsx (1)

      19-19: Consider safer initialization pattern.

      The non-null assertion (null!) could lead to runtime errors if invoices is accessed before initialization completes. While the current usage with ensureInvoices() appears safe, this is fragile.

      Consider initializing as:

      -let invoices: Array<Invoice> = null!
      +let invoices: Array<Invoice> | undefined = undefined

      Then add a guard in fetchInvoices and fetchInvoiceById if needed.

      examples/solid/authenticated-routes/index.html (1)

      1-12: Consider updating the title to be more descriptive.

      The generic "Vite App" title could be more descriptive, e.g., "TanStack Router - Authenticated Routes Example".

      Apply this diff:

      -    <title>Vite App</title>
      +    <title>TanStack Router - Authenticated Routes Example</title>
      examples/solid/authenticated-routes/src/routes/login.tsx (1)

      13-14: Remove unnecessary const assertion.

      The as const assertion on a string literal is redundant since TypeScript already infers the exact literal type '/dashboard'. The eslint-disable comment confirms this is unnecessary.

      -// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
      -const fallback = '/dashboard' as const
      +const fallback = '/dashboard'
      📜 Review details

      Configuration used: CodeRabbit UI

      Review profile: CHILL

      Plan: Pro

      📥 Commits

      Reviewing files that changed from the base of the PR and between f0e02799ce6c45d5257ad319f010141fecde6116 and 5feb7e266f3c8c50fc17c14b61653cfc71cc4b57.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (22)
      • examples/solid/authenticated-routes/.gitignore (1 hunks)
      • examples/solid/authenticated-routes/.vscode/settings.json (1 hunks)
      • examples/solid/authenticated-routes/README.md (1 hunks)
      • examples/solid/authenticated-routes/index.html (1 hunks)
      • examples/solid/authenticated-routes/package.json (1 hunks)
      • examples/solid/authenticated-routes/postcss.config.mjs (1 hunks)
      • examples/solid/authenticated-routes/src/auth.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/main.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/posts.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routeTree.gen.ts (1 hunks)
      • examples/solid/authenticated-routes/src/routes/__root.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/_auth.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/index.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/routes/login.tsx (1 hunks)
      • examples/solid/authenticated-routes/src/styles.css (1 hunks)
      • examples/solid/authenticated-routes/src/utils.ts (1 hunks)
      • examples/solid/authenticated-routes/tsconfig.json (1 hunks)
      • examples/solid/authenticated-routes/vite.config.js (1 hunks)
      🧰 Additional context used
      📓 Path-based instructions (4)
      examples/{react,solid}/**

      📄 CodeRabbit inference engine (AGENTS.md)

      Keep example applications under examples/react/ and examples/solid/

      Files:

      • examples/solid/authenticated-routes/README.md
      • examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx
      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/index.html
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx
      • examples/solid/authenticated-routes/src/routes/__root.tsx
      • examples/solid/authenticated-routes/src/utils.ts
      • examples/solid/authenticated-routes/src/styles.css
      • examples/solid/authenticated-routes/src/routes/login.tsx
      • examples/solid/authenticated-routes/postcss.config.mjs
      • examples/solid/authenticated-routes/src/posts.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.tsx
      • examples/solid/authenticated-routes/src/main.tsx
      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
      • examples/solid/authenticated-routes/tsconfig.json
      • examples/solid/authenticated-routes/src/auth.tsx
      • examples/solid/authenticated-routes/package.json
      • examples/solid/authenticated-routes/vite.config.js
      **/*.{ts,tsx}

      📄 CodeRabbit inference engine (AGENTS.md)

      Use TypeScript in strict mode with extensive type safety across the codebase

      Files:

      • examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx
      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx
      • examples/solid/authenticated-routes/src/routes/__root.tsx
      • examples/solid/authenticated-routes/src/utils.ts
      • examples/solid/authenticated-routes/src/routes/login.tsx
      • examples/solid/authenticated-routes/src/posts.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.tsx
      • examples/solid/authenticated-routes/src/main.tsx
      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
      • examples/solid/authenticated-routes/src/auth.tsx
      **/src/routes/**

      📄 CodeRabbit inference engine (AGENTS.md)

      Place file-based routes under src/routes/ directories

      Files:

      • examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx
      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx
      • examples/solid/authenticated-routes/src/routes/__root.tsx
      • examples/solid/authenticated-routes/src/routes/login.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
      **/package.json

      📄 CodeRabbit inference engine (AGENTS.md)

      Use workspace:* protocol for internal dependencies in package.json files

      Files:

      • examples/solid/authenticated-routes/package.json
      🧠 Learnings (10)
      📓 Common learnings
      Learnt from: CR
      Repo: TanStack/router PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-09-23T17:36:12.598Z
      Learning: Applies to packages/{react-router,solid-router}/** : Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/
      Learnt from: FatahChan
      Repo: TanStack/router PR: 5475
      File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0
      Timestamp: 2025-10-14T18:59:33.990Z
      Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.
      📚 Learning: 2025-10-01T18:31:35.420Z
      Learnt from: schiller-manuel
      Repo: TanStack/router PR: 5330
      File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61
      Timestamp: 2025-10-01T18:31:35.420Z
      Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.

      Applied to files:

      • examples/solid/authenticated-routes/.vscode/settings.json
      • examples/solid/authenticated-routes/.gitignore
      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx
      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
      • examples/solid/authenticated-routes/tsconfig.json
      📚 Learning: 2025-10-08T08:11:47.088Z
      Learnt from: nlynzaad
      Repo: TanStack/router PR: 5402
      File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
      Timestamp: 2025-10-08T08:11:47.088Z
      Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.

      Applied to files:

      • examples/solid/authenticated-routes/.vscode/settings.json
      • examples/solid/authenticated-routes/.gitignore
      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
      • examples/solid/authenticated-routes/tsconfig.json
      📚 Learning: 2025-09-23T17:36:12.598Z
      Learnt from: CR
      Repo: TanStack/router PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-09-23T17:36:12.598Z
      Learning: Applies to packages/{react-router,solid-router}/** : Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/

      Applied to files:

      • examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx
      • examples/solid/authenticated-routes/.gitignore
      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx
      • examples/solid/authenticated-routes/src/routes/__root.tsx
      • examples/solid/authenticated-routes/src/routes/login.tsx
      • examples/solid/authenticated-routes/src/routes/_auth.tsx
      • examples/solid/authenticated-routes/src/main.tsx
      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
      • examples/solid/authenticated-routes/tsconfig.json
      • examples/solid/authenticated-routes/package.json
      • examples/solid/authenticated-routes/vite.config.js
      📚 Learning: 2025-09-23T17:36:12.598Z
      Learnt from: CR
      Repo: TanStack/router PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-09-23T17:36:12.598Z
      Learning: Applies to **/src/routes/** : Place file-based routes under src/routes/ directories

      Applied to files:

      • examples/solid/authenticated-routes/src/routes/index.tsx
      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      📚 Learning: 2025-10-01T18:30:26.591Z
      Learnt from: schiller-manuel
      Repo: TanStack/router PR: 5330
      File: packages/router-core/src/router.ts:2231-2245
      Timestamp: 2025-10-01T18:30:26.591Z
      Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.

      Applied to files:

      • examples/solid/authenticated-routes/src/routes/_auth.tsx
      📚 Learning: 2025-09-23T17:36:12.598Z
      Learnt from: CR
      Repo: TanStack/router PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-09-23T17:36:12.598Z
      Learning: Applies to packages/{router-cli,router-generator,router-plugin,virtual-file-routes}/** : Keep CLI, generators, bundler plugins, and virtual file routing utilities in their dedicated tooling package directories

      Applied to files:

      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/package.json
      📚 Learning: 2025-11-02T16:16:24.898Z
      Learnt from: nlynzaad
      Repo: TanStack/router PR: 5732
      File: packages/start-client-core/src/client/hydrateStart.ts:6-9
      Timestamp: 2025-11-02T16:16:24.898Z
      Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.

      Applied to files:

      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      • examples/solid/authenticated-routes/tsconfig.json
      • examples/solid/authenticated-routes/package.json
      📚 Learning: 2025-09-23T17:36:12.598Z
      Learnt from: CR
      Repo: TanStack/router PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-09-23T17:36:12.598Z
      Learning: Applies to packages/router-core/** : Keep framework-agnostic core router logic in packages/router-core/

      Applied to files:

      • examples/solid/authenticated-routes/src/routeTree.gen.ts
      📚 Learning: 2025-09-23T17:36:12.598Z
      Learnt from: CR
      Repo: TanStack/router PR: 0
      File: AGENTS.md:0-0
      Timestamp: 2025-09-23T17:36:12.598Z
      Learning: Applies to **/*.{ts,tsx} : Use TypeScript in strict mode with extensive type safety across the codebase

      Applied to files:

      • examples/solid/authenticated-routes/tsconfig.json
      🧬 Code graph analysis (10)
      examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx (2)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
      • Route (11-23)
      examples/solid/authenticated-routes/src/auth.tsx (1)
      • useAuth (57-63)
      examples/solid/authenticated-routes/src/routes/index.tsx (6)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1)
      • Route (5-12)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1)
      • Route (5-10)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
      • Route (11-23)
      examples/solid/authenticated-routes/src/routes/login.tsx (1)
      • Route (16-26)
      examples/solid/authenticated-routes/src/routes/__root.tsx (1)
      • Route (10-17)
      examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx (1)
      • Route (5-7)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (3)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1)
      • Route (5-12)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1)
      • Route (5-10)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
      • Route (11-23)
      examples/solid/authenticated-routes/src/routes/__root.tsx (1)
      examples/solid/authenticated-routes/src/auth.tsx (1)
      • AuthContext (5-10)
      examples/solid/authenticated-routes/src/routes/login.tsx (3)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
      • Route (11-23)
      examples/solid/authenticated-routes/src/auth.tsx (1)
      • useAuth (57-63)
      examples/solid/authenticated-routes/src/utils.ts (1)
      • sleep (1-3)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (4)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1)
      • Route (5-10)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
      • Route (11-23)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1)
      • Route (3-5)
      examples/solid/authenticated-routes/src/posts.tsx (1)
      • fetchInvoiceById (40-50)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (2)
      examples/solid/authenticated-routes/src/routes/login.tsx (1)
      • Route (16-26)
      examples/solid/authenticated-routes/src/auth.tsx (1)
      • useAuth (57-63)
      examples/solid/authenticated-routes/src/main.tsx (1)
      examples/solid/authenticated-routes/src/auth.tsx (2)
      • useAuth (57-63)
      • AuthProvider (28-55)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (4)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1)
      • Route (5-12)
      examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
      • Route (11-23)
      examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1)
      • Route (3-5)
      examples/solid/authenticated-routes/src/posts.tsx (1)
      • fetchInvoices (36-38)
      examples/solid/authenticated-routes/src/auth.tsx (1)
      examples/solid/authenticated-routes/src/utils.ts (1)
      • sleep (1-3)
      🔇 Additional comments (21)
      examples/solid/authenticated-routes/tsconfig.json (1)

      1-12: TypeScript configuration is properly set up for Solid.js.

      The configuration correctly enables strict mode, preserves JSX for Solid's compiler, and targets modern JavaScript with appropriate library definitions. All settings align with TanStack Router's TypeScript standards and Solid.js requirements.

      examples/solid/authenticated-routes/.gitignore (1)

      1-5: LGTM! Standard and appropriate .gitignore entries.

      The file includes all necessary exclusions for a Solid.js + Vite project: dependencies, build outputs, OS-specific files, and local config. The ordering is logical and the patterns are correct.

      examples/solid/authenticated-routes/vite.config.js (1)

      1-14: LGTM! Clean Vite configuration for Solid.js with TanStack Router.

      The configuration is well-structured:

      • Plugin order is correct (TanStack Router plugin before Solid plugin ensures route files are transformed first)
      • autoCodeSplitting: true is a good default for examples, demonstrating best practices
      • Minimal and focused, appropriate for an example project
      examples/solid/authenticated-routes/.vscode/settings.json (1)

      1-11: LGTM!

      The VSCode settings appropriately handle the autogenerated routeTree.gen.ts file by excluding it from watchers/search and marking it as readonly to prevent accidental modifications.

      examples/solid/authenticated-routes/src/utils.ts (1)

      1-3: LGTM!

      The sleep utility function is correctly implemented for introducing asynchronous delays.

      examples/solid/authenticated-routes/postcss.config.mjs (1)

      1-5: LGTM!

      Standard PostCSS configuration for Tailwind CSS v4 integration.

      examples/solid/authenticated-routes/src/posts.tsx (2)

      23-34: LGTM!

      The lazy initialization pattern with shared promise prevents duplicate fetches and handles concurrent access correctly.


      36-50: LGTM!

      The exported functions correctly apply the loader delay and handle the invoice not found case with an appropriate error.

      examples/solid/authenticated-routes/src/styles.css (1)

      1-21: LGTM!

      The Tailwind CSS v4 syntax is correctly used with the new @import 'tailwindcss' directive, @layer, @apply, and standard utility classes.

      examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1)

      1-5: LGTM!

      The index route correctly provides a placeholder message when no invoice is selected. The route definition follows TanStack Router conventions and appropriately relies on the parent route's loader for data.

      examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (2)

      5-10: LGTM!

      The route definition correctly uses the loader pattern to fetch invoices asynchronously and the structure follows TanStack Router conventions.


      12-42: LGTM!

      The component correctly accesses loader data via signal accessor, implements a responsive layout using Tailwind CSS v4, and properly sets up nested routing with the Outlet. The invoice list rendering and link navigation are well-structured.

      examples/solid/authenticated-routes/src/auth.tsx (4)

      5-10: LGTM!

      The AuthContext interface is well-defined with appropriate method signatures for authentication operations.


      12-14: LGTM!

      The context initialization with null default is appropriate given the useAuth hook enforces usage within the provider.


      16-26: LGTM!

      The storage helper functions correctly handle reading and writing user data to localStorage, including proper cleanup when user is null.


      57-63: LGTM!

      The useAuth hook correctly enforces usage within the AuthProvider with a clear error message.

      examples/solid/authenticated-routes/src/routes/login.tsx (2)

      16-26: LGTM!

      The route definition correctly validates the search params with Zod, implements a beforeLoad guard to redirect authenticated users, and follows TanStack Router conventions.


      28-97: LGTM!

      The login component correctly handles form submission, authentication flow, and navigation. The acknowledged sleep(1) hack on line 52 is acceptable for an example application demonstrating authentication patterns.

      examples/solid/authenticated-routes/src/routes/_auth.tsx (2)

      11-23: LGTM!

      The beforeLoad guard correctly implements authentication checking and redirects unauthenticated users to the login page while preserving the intended destination.


      25-71: LGTM!

      The AuthLayout component correctly implements the logout flow with user confirmation and proper promise chaining. The navigation structure and Outlet placement are appropriate for the authenticated route layout.

      examples/solid/authenticated-routes/src/routeTree.gen.ts (1)

      1-195: Skipping review of generated file.

      This file is autogenerated by TanStack Router and should not be manually modified or reviewed. Based on learnings.

      examples/solid/authenticated-routes/package.json lines 13 to 15
      @@ -0,0 +1,15 @@
      1+{
      2+ "name": "tanstack-router-solid-example-authenticated-routes",
      3+ "private": true,
      4+ "type": "module",
      5+ "scripts": {
      6+ "dev": "vite --port 3000",
      7+ "build": "vite build && tsc --noEmit",
      8+ "serve": "vite preview",
      9+ "start": "vite"
      10+ },
      11+ "dependencies": {
      12+ "@tailwindcss/postcss": "^4.1.15",
      13+ "@tanstack/solid-router": "^1.135.2",
      14+ "@tanstack/solid-router-devtools": "^1.135.2",
      15+ "@tanstack/router-plugin": "^1.135.2",

      ⚠️ Potential issue | 🟠 Major

      Use workspace:* protocol for internal TanStack dependencies.

      Internal monorepo dependencies should use the workspace:* protocol instead of version ranges to ensure proper monorepo dependency resolution.

      As per coding guidelines.

      Apply this diff:

      -    "@tanstack/solid-router": "^1.135.2",
      -    "@tanstack/solid-router-devtools": "^1.135.2",
      -    "@tanstack/router-plugin": "^1.135.2",
      +    "@tanstack/solid-router": "workspace:*",
      +    "@tanstack/solid-router-devtools": "workspace:*",
      +    "@tanstack/router-plugin": "workspace:*",
      📝 Committable suggestion

      ‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

          "@tanstack/solid-router": "workspace:*",
          "@tanstack/solid-router-devtools": "workspace:*",
          "@tanstack/router-plugin": "workspace:*",
      🤖 Prompt for AI Agents
      In examples/solid/authenticated-routes/package.json around lines 13 to 15 the
      internal TanStack dependencies use version ranges; replace the version ranges
      for "@tanstack/solid-router", "@tanstack/solid-router-devtools", and
      "@tanstack/router-plugin" with the workspace:* protocol so they read as
      workspace:* to ensure monorepo dependency resolution per guidelines.
      examples/solid/authenticated-routes/src/auth.tsx lines 46 to 48
      @@ -0,0 +28,21 @@
      28+export function AuthProvider(props: { children: Solid.JSX.Element }) {
      29+ const [user, setUser] = Solid.createSignal<string | null>(getStoredUser())
      30+ const isAuthenticated = () => !!user()
      31+
      32+ const logout = async () => {
      33+ await sleep(250)
      34+
      35+ setStoredUser(null)
      36+ setUser(null)
      37+ }
      38+
      39+ const login = async (username: string) => {
      40+ await sleep(500)
      41+
      42+ setStoredUser(username)
      43+ setUser(username)
      44+ }
      45+
      46+ Solid.createEffect(() => {
      47+ setUser(getStoredUser())
      48+ })

      ⚠️ Potential issue | 🟡 Minor

      Remove or properly implement the createEffect for storage synchronization.

      This effect runs on every render cycle and redundantly reads from localStorage without any dependencies. The initial user state is already correctly initialized from storage on line 29.

      If the intent is to synchronize authentication state across browser tabs, implement a proper storage event listener instead:

      -  Solid.createEffect(() => {
      -    setUser(getStoredUser())
      -  })
      +  Solid.onMount(() => {
      +    const handleStorageChange = (e: StorageEvent) => {
      +      if (e.key === key) {
      +        setUser(e.newValue)
      +      }
      +    }
      +    window.addEventListener('storage', handleStorageChange)
      +    Solid.onCleanup(() => window.removeEventListener('storage', handleStorageChange))
      +  })

      Alternatively, if cross-tab sync is not needed, simply remove the effect.

      Committable suggestion skipped: line range outside the PR's diff.

      🤖 Prompt for AI Agents
      In examples/solid/authenticated-routes/src/auth.tsx around lines 46 to 48, the
      Solid.createEffect currently reads localStorage on every render; remove this
      effect or replace it with a single-run mount handler that either (a) removes the
      Solid.createEffect entirely since initial state is already set from storage on
      line 29, or (b) implements proper cross-tab sync by adding a
      window.addEventListener('storage', ...) on mount that checks the auth key, calls
      setUser(getStoredUser()) when that key changes, and removes the listener on
      cleanup so it only runs in response to storage events rather than every render.
      examples/solid/authenticated-routes/src/posts.tsx lines 3 to 11
      @@ -0,0 +1,11 @@
      1+import axios from 'redaxios'
      2+
      3+async function loaderDelayFn<T>(fn: (...args: Array<any>) => Promise<T> | T) {
      4+ const delay = Number(sessionStorage.getItem('loaderDelay') ?? 0)
      5+ const delayPromise = new Promise((r) => setTimeout(r, delay))
      6+
      7+ await delayPromise
      8+ const res = await fn()
      9+
      10+ return res
      11+}

      ⚠️ Potential issue | 🟡 Minor

      Fix the loaderDelayFn parameter signature.

      The function signature declares fn: (...args: Array<any>) suggesting it accepts arguments, but Line 8 calls fn() without passing any arguments. This is misleading and could cause issues if a function expecting parameters is passed in.

      Apply this diff to fix the signature:

      -async function loaderDelayFn<T>(fn: (...args: Array<any>) => Promise<T> | T) {
      +async function loaderDelayFn<T>(fn: () => Promise<T> | T) {
      📝 Committable suggestion

      ‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

      async function loaderDelayFn<T>(fn: () => Promise<T> | T) {
        const delay = Number(sessionStorage.getItem('loaderDelay') ?? 0)
        const delayPromise = new Promise((r) => setTimeout(r, delay))
      
        await delayPromise
        const res = await fn()
      
        return res
      }
      🤖 Prompt for AI Agents
      In examples/solid/authenticated-routes/src/posts.tsx around lines 3 to 11, the
      loaderDelayFn parameter is typed as fn: (...args: Array<any>) which implies it
      expects arguments but the implementation always calls fn() with no args; change
      the parameter signature to fn: () => Promise<T> | T so it correctly represents a
      no-argument callback (update the type only, leaving the call site as fn()).
      examples/solid/authenticated-routes/src/routes/index.tsx lines 33 to 39
      @@ -0,0 +19,21 @@
      19+ adapt then to work with your authentication flow/system for your app.
      20+ </p>
      21+ <p>
      22+ You are currently on the index route of the{' '}
      23+ <strong>authenticated-routes</strong> example.
      24+ </p>
      25+ <p>You can try going through these options.</p>
      26+ <ol class="list-disc list-inside px-2">
      27+ <li>
      28+ <Link to="/login" class="text-blue-500 hover:opacity-75">
      29+ Go to the public login page.
      30+ </Link>
      31+ </li>
      32+ <li>
      33+ <Link to="/dashboard" class="text-blue-500 hover:opacity-75">
      34+ Go to the auth-only dashboard page.
      35+ </Link>
      36+ </li>
      37+ <li>
      38+ <Link to="/invoices" class="text-blue-500 hover:opacity-75">
      39+ Go to the auth-only invoices page.

      ⚠️ Potential issue | 🔴 Critical

      Fix dashboard/invoices link targets.

      These links point to /dashboard and /invoices, but the only registered routes are /_auth/dashboard and /_auth/invoices. Clicking them currently lands on an undefined route, so users never reach the protected pages or their guards. Update the to values to the actual paths.

      -          <Link to="/dashboard" class="text-blue-500 hover:opacity-75">
      +          <Link to="/_auth/dashboard" class="text-blue-500 hover:opacity-75">
                   Go to the auth-only dashboard page.
                 </Link>
               </li>
               <li>
      -          <Link to="/invoices" class="text-blue-500 hover:opacity-75">
      +          <Link to="/_auth/invoices" class="text-blue-500 hover:opacity-75">
                   Go to the auth-only invoices page.
                 </Link>
      📝 Committable suggestion

      ‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

                <Link to="/_auth/dashboard" class="text-blue-500 hover:opacity-75">
                  Go to the auth-only dashboard page.
                </Link>
              </li>
              <li>
                <Link to="/_auth/invoices" class="text-blue-500 hover:opacity-75">
                  Go to the auth-only invoices page.
      🤖 Prompt for AI Agents
      In examples/solid/authenticated-routes/src/routes/index.tsx around lines 33 to
      39, the Link components point to /dashboard and /invoices but the app registers
      routes at /_auth/dashboard and /_auth/invoices; update the Link `to` props to
      use the actual registered paths /_auth/dashboard and /_auth/invoices so clicks
      navigate to the protected pages and their guards.

Sign in to join this conversation.