Skip to content

Non-zero runtime overhead in production build #112

Closed

Description

@vasilii-kovalev

TanStack Devtools version

v0.6.4

Framework/Library version

React v19.1.1

Describe the bug and the steps to reproduce it

After creating a production build, I can see a non-zero overhead from the devtools library and its plugins:

Image

Since the devtools are available in development mode only, this overhead should not exist in the production build.

Actually, all devtools components add this overhead, not only TanStack Devtools, so let me know if I should create separate issues in the other libraries.

A workaround is to render the devtools components conditionally depending on the environment variable:

import {
  TanStackDevtools,
} from "@tanstack/react-devtools";
import {
  ReactQueryDevtoolsPanel,
} from "@tanstack/react-query-devtools";
import {
  TanStackRouterDevtoolsPanel,
} from "@tanstack/react-router-devtools";

<Fragment>
  {
    import.meta.env.DEV
      ? (
        <TanStackDevtools
          plugins={[
            {
              name: "TanStack Query",
              render: (
                <ReactQueryDevtoolsPanel
                  client={queryClient}
                />
              ),
            },
            {
              name: "TanStack Router",
              render: (
                <TanStackRouterDevtoolsPanel
                  router={router}
                />
              ),
            },
          ]}
        />
      )
      : null
  }
</Fragment>

Steps to reproduce:

  1. Create a Vite (React + TypeScript) project
  2. (Optional) Add TanStack Query and TanStack Router with devtools
  3. Set up the devtools as written in the documentation
  4. Make a production build
  5. Analyze the production build (using Sonda, for example)

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

vasilii-kovalev/state-manager-examples@63b84aa

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Activity

  1. sprusak commented on Sep 8, 2025

    @sprusak
    Contributor

    Hi, just from my perspective, this minimal footprint is basically just export of empty function. (not noticeable by most of the apps)

    As you suggested to completely remove it from the bundle, some adjustments should be done on application side, but this could be rather some part of documentation as from lib perspective it is probably hard to reduce it more. For reference this is the index file https://github.com/TanStack/devtools/blob/main/packages/react-devtools/src/index.ts

  2. vasilii-kovalev commented on Sep 8, 2025

    @vasilii-kovalev
    Author

    @sprusak, thank you for the clarification!
    In your opinion, does it make sense to mention the workaround in the documentation?

  3. AlemTuzlak commented on Sep 8, 2025

    @AlemTuzlak
    Collaborator

    Tbh I'm not sure if this can be easily done outside the bundler, I do have some ideas I want to explore like moving the logic to vite instead of the actual libs, tree-shaking it completely out and not using it at all indeed would require something like this on the user-side.

  4. added a commit that references this issue on Sep 18, 2025
    2b77ace
  5. vasilii-kovalev commented on Sep 18, 2025

    @vasilii-kovalev
    Author

    After updating to the latest versions of devtools-related packages, Sonda highlights the following issue on build:

    [plugin @tanstack/devtools:remove-devtools-on-build] Sourcemap is likely to be incorrect: a plugin (@tanstack/devtools:remove-devtools-on-build) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help

    main.tsx:

    import {
      TanStackDevtools,
    } from "@tanstack/react-devtools";
    import {
      QueryClient,
      QueryClientProvider,
    } from "@tanstack/react-query";
    import {
      ReactQueryDevtoolsPanel,
    } from "@tanstack/react-query-devtools";
    import {
      createRouter,
      RouterProvider,
    } from "@tanstack/react-router";
    import {
      TanStackRouterDevtoolsPanel,
    } from "@tanstack/react-router-devtools";
    import {
      StrictMode,
    } from "react";
    import {
      createRoot,
    } from "react-dom/client";
    
    import {
      isNull,
    } from "@/utilities/is-null";
    
    import {
      routeTree,
    } from "./routeTree.gen";
    
    const router = createRouter({
      routeTree,
    });
    
    declare module "@tanstack/react-router" {
      interface Register {
        router: typeof router;
      }
    }
    
    const queryClient = new QueryClient({
      defaultOptions: {
        queries: {
          refetchOnWindowFocus: false,
        },
      },
    });
    
    const rootElement = document.getElementById("root");
    
    if (!isNull(rootElement)) {
      const root = createRoot(rootElement);
    
      root.render(
        <StrictMode>
          <QueryClientProvider
            client={queryClient}
          >
            <RouterProvider
              router={router}
            />
    
            <TanStackDevtools
              plugins={[
                {
                  name: "TanStack Query",
                  render: <ReactQueryDevtoolsPanel/>,
                },
                {
                  name: "TanStack Router",
                  render: (
                    <TanStackRouterDevtoolsPanel
                      router={router}
                    />
                  ),
                },
              ]}
            />
          </QueryClientProvider>
        </StrictMode>,
      );
    }

    vite.config.ts:

    import {
      devtools,
    } from "@tanstack/devtools-vite";
    import {
      tanstackRouter,
    } from "@tanstack/router-plugin/vite";
    import react from "@vitejs/plugin-react";
    import sonda from "sonda/vite";
    import unoCSS from "unocss/vite";
    import {
      defineConfig,
    } from "vite";
    import tsconfigPaths from "vite-tsconfig-paths";
    
    // https://vite.dev/config
    const config = defineConfig({
      build: {
        // Required for Sonda.
        sourcemap: true,
      },
      plugins: [
        devtools(),
        tsconfigPaths({
          configNames: [
            "tsconfig.app.json",
          ],
        }),
        tanstackRouter({
          autoCodeSplitting: true,
          target: "react",
        }),
        react({
          babel: {
            plugins: [
              "babel-plugin-react-compiler",
            ],
          },
        }),
        unoCSS(),
        sonda(),
      ],
    });
    
    export default config;

    The same with Solid setup.
    It didn't happen before the update.
    Repository for reproduction.

    Is it a bug on devtools packages' side?

  6. AlemTuzlak commented on Sep 18, 2025

    @AlemTuzlak
    Collaborator

    @vasilii-kovalev no, it's a bug in start, if you try it with the latest alpha it goes away, although there are a few warnings in the latest alpha that are improvements that need to be made on my side which I'm actively working on

  7. AlemTuzlak commented on Sep 19, 2025

    @AlemTuzlak
    Collaborator

    @vasilii-kovalev this PR will bring true 0 production overhead and issues:
    https://github.com/TanStack/devtools/pull/148/files

  8. vasilii-kovalev commented on Sep 19, 2025

    @vasilii-kovalev
    Author

    @vasilii-kovalev this PR will bring true 0 production overhead and issues: https://github.com/TanStack/devtools/pull/148/files

    Sadly, still seeing the warning, and having broken sourcemaps after updating to the latest version after the fix.

  9. AlemTuzlak commented on Sep 19, 2025

    @AlemTuzlak
    Collaborator

    interesting, sourcemaps are generated by babel, not sure why it reports them as broken, i'll try to figure it out

  10. AlemTuzlak commented on Sep 19, 2025

    @AlemTuzlak
    Collaborator

    okay figured it out, will release a fix in next minor

  11. vasilii-kovalev commented on Sep 19, 2025

    @vasilii-kovalev
    Author

    After the latest update, devtools are indeed removed from production build, and the sourcemaps are correct. Thank you for your perseverance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions