Skip to content

Conversation

noahsilas
Copy link
Contributor

@noahsilas noahsilas commented Sep 1, 2025

When using an anonymous component, Vite's hot reloading doesn't always immediately pick up changes made to the component. This can be confusing to someone testing out the router.

By extracting a named component, Vite seems to be able to match updates to the component to the mounted instance and apply hot reloading as expected.

Summary by CodeRabbit

  • Documentation
    • Updated the React quick-start guide to use a named RootLayout component in example code instead of an inline anonymous component, improving clarity and aligning with best practices.
    • Clarifies component structure in the root route example for easier comprehension and reuse.
    • No changes to behavior or UI; this is a readability and maintainability improvement in the docs.

When using an anonymous component, Vite's hot reloading doesn't always immediately pick up changes made to the component. This can be confusing to someone testing out the router.

By extracting a named component, Vite seems to be able to match updates to the component to the mounted instance and apply hot reloading as expected.
@github-actions github-actions bot added the documentation Everything documentation related label Sep 1, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Refactors the React router quick-start documentation snippet to extract the inline root component into a named RootLayout and reference it via createRootRoute({ component: RootLayout }). No other documentation content changes.

Changes

Cohort / File(s) Summary
Docs: React Router Quick Start
docs/router/framework/react/quick-start.md
Inline anonymous component in __root.tsx example replaced with a named RootLayout, and createRootRoute now references component: RootLayout instead of an inline function. No UI/behavioral changes; documentation content otherwise unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

I hop through docs with tidy feet,
Inline roots now feel complete.
RootLayout named, a cleaner view,
Same old trail, just clearer too.
Thump-thump—refactor neat! 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
docs/router/framework/react/quick-start.md (2)

95-95: Nit: drop the trailing semicolon for consistency with surrounding snippets

Most TSX snippets in this doc omit semicolons. Consider aligning style.

Apply:

-export const Route = createRootRoute({ component: RootLayout });
+export const Route = createRootRoute({ component: RootLayout })

79-95: Mirror this pattern in the code-based config example below for consistency/HMR

The “Using Code-Based Route Configuration” section still uses an inline anonymous component for createRootRoute. Suggest mirroring the named-component pattern to avoid mixed guidance and ensure Fast Refresh behaves consistently.

Proposed snippet for that section:

const RootLayout = () => (
  <>
    <div className="p-2 flex gap-2">
      <Link to="/" className="[&.active]:font-bold">Home</Link>{' '}
      <Link to="/about" className="[&.active]:font-bold">About</Link>
    </div>
    <hr />
    <Outlet />
    <TanStackRouterDevtools />
  </>
)

const rootRoute = createRootRoute({
  component: RootLayout,
})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 79fe58f and acfcbca.

📒 Files selected for processing (1)
  • docs/router/framework/react/quick-start.md (1 hunks)
🔇 Additional comments (1)
docs/router/framework/react/quick-start.md (1)

79-93: Good change: extracted named RootLayout improves React Fast Refresh/HMR reliability

Moving the inline anonymous component to a named RootLayout is a solid docs fix and matches how Vite’s Fast Refresh tracks components.

@noahsilas
Copy link
Contributor Author

As an aside, I tried to generate this locally to view the ultimate result, but got a bit stuck. So, I'd encourage someone who does have this working to check this out and look at how it renders. I think it should be pretty safe, but I don't love pushing without seeing it 😬

I saw in Contributing.md that this should be tested via the tanstack.com repo (

router/CONTRIBUTING.md

Lines 26 to 27 in 79fe58f

- Editing the docs locally and previewing the changes
- The documentations for all the TanStack projects are hosted on [tanstack.com](https://tanstack.com), which is a TanStack Start application (https://github.com/TanStack/tanstack.com). You need to run this app locally to preview your changes in the `TanStack/router` docs.
). I checked that out and followed the README instructions, but trying to run pnpm dev crashes:

Error: opts.convexSiteUrl is required
    at reactStartHelpers (/Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/@convex-dev+better-auth@0.7.15_better-auth@1.3.7_react-dom@19.0.0_react@19.0.0__react@19.0.0__myw7fjiqrbqhpfwwmqola5zot4/node_modules/@convex-dev/better-auth/src/react-start/index.ts:75:11)
    at eval (/Users/noah/src/tanstack/tanstack.com/src/server/auth.server.ts:35:3)
    at async ESModulesEvaluator.runInlinedModule (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js:1062:5)
    at async ModuleRunner.directRequest (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js:1284:61)
    at async ModuleRunner.cachedRequest (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js:1180:76)
    at async eval (/Users/noah/src/tanstack/tanstack.com/src/routes/api/auth/$.ts:1:1)
    at async ESModulesEvaluator.runInlinedModule (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js:1062:5)
    at async ModuleRunner.directRequest (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js:1284:61)
    at async ModuleRunner.cachedRequest (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/module-runner.js:1180:76)
    at async eval (/Users/noah/src/tanstack/tanstack.com/src/routeTree.gen.ts:66:1)
file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:5026
        throw new Error(LINE_GTR_ZERO);
              ^

Error: `line` must be greater than 0 (lines start at line 1)
    at originalPositionFor$1 (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:5026:15)
    at file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:25085:21
    at String.replace (<anonymous>)
    at file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:25075:17
    at Array.map (<anonymous>)
    at ssrRewriteStacktrace (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:25074:28)
    at ssrFixStacktrace (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:25125:22)
    at Proxy.ssrFixStacktrace (file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/vite@6.3.5_@types+node@24.3.0_jiti@2.5.1_lightningcss@1.30.1_terser@5.43.1_tsx@4.20.4_yaml@2.8.1/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:38480:7)
    at file:///Users/noah/src/tanstack/tanstack.com/node_modules/.pnpm/@tanstack+start-plugin-core@1.131.27_@netlify+blobs@10.0.8_@tanstack+react-router@1.131.27_re_sozgr6bn6uehq3ilb54s3x6jg4/node_modules/@tanstack/start-plugin-core/dist/esm/dev-server-plugin/plugin.js:51:27

This looks like a pretty recent addition (first usage I see of convexSiteUrl is in commit 864b7f3, with some other movement after that). Maybe there's something easy to do to set up the convex site url locally that can be added to the README?

@schiller-manuel schiller-manuel merged commit 0ee993b into TanStack:main Sep 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Everything documentation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants