Skip to content

Render TanStack DevTools only in development mode #849

Description

@thetelgote

Problem

Problem

The root route currently renders TanStackDevtools unconditionally in apps/web/src/routes/__root.tsx.

Since TanStack DevTools are primarily intended for development and debugging, rendering them in production is unnecessary and may introduce avoidable overhead.

Although the DevTools UI is typically inactive in production, conditionally rendering the component would better align with the intended usage and keep production builds focused on end users.

Solution

Proposed Solution

Render TanStackDevtools only when running in development mode by wrapping it with Vite's development flag.

Example:

{import.meta.env.DEV && (
  <TanStackDevtools
    config={{
      position: 'bottom-right',
    }}
    plugins={[
      {
        name: 'Tanstack Router',
        render: <TanStackRouterDevtoolsPanel />,
      },
    ]}
  />
)}

This change would:

  • Render DevTools only during development.
  • Keep production output cleaner.
  • Preserve the current development experience.
  • Require only a small, backward-compatible code change.

Alternative

Alternatives Considered

An alternative would be to keep the current behavior since the DevTools are not actively used by end users.

Another option would be to introduce a configuration flag to explicitly enable or disable DevTools, but using import.meta.env.DEV is simpler and follows common Vite practices.

Anything else?

This would be a small refactoring with no functional changes to the application itself.

I'd be happy to work on this change and submit a pull request if the maintainers agree that it aligns with the project's goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions