Skip to content
Source
Sign inSign up
TanStack/query

@tanstack/react-query-devtools v4 does not include `NODE_ENV` check #3860

Send to my agent
Closedjaworek(GitHub profile, opens in a new tab) opened this issue 10 comments

Describe the bug

According to the documention, devtools should only be included in development mode: https://tanstack.com/query/v4/docs/devtools#install-and-import-the-devtools

React Query v3 devtools include check for that: https://github.com/TanStack/query/blob/v3/devtools/index.js

React Query v4 are missing this check which results in devtools being bundled in production and increasing overall bundle size: https://github.com/TanStack/query/blob/main/packages/react-query-devtools/src/index.ts

Your minimal, reproducible example

https://stackblitz.com/edit/nextjs-odbs3c?file=pages/_app.js

React Query v3 does not have this issue: https://stackblitz.com/edit/nextjs-ssq6g3?file=pages/_app.js

Steps to reproduce

  1. Open _app.js file
  2. Open terminal and run npm run build
  3. Comment out <ReactQueryDevtools initialIsOpen={false} /> and import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
  4. Run npm run build
  5. Notice that shared bundle size decreased from 103kB to 90kB

Expected behavior

React Query Devtools should not be bundled in production build by default.

How often does this bug happen?

Every time

Screenshots or Videos

Next 12.2 project with devtools enabled: image

Next 12.2 project with devtools disabled: image

Platform

  • OS: MacOS
  • Browser: Chromium
  • Version: 4.0.3

react-query version

4.0.3

TypeScript version

4.7.4

Additional context

No response

  1. TkDodo added labelsbug

  2. TkDodo added labelspackage: react-query-devtools

  3. I re-created what we had in v3 here: https://github.com/TanStack/query/pull/3861

    but it doesn't seem to work well with ESM. Do you have a better idea?

  4. I am guessing this issue also causes these failures in my tests too:

    Screenshot 2022-07-20 at 10 08 01
  5. @jaworek can you try it out with this codesandbox preview build?

    "@tanstack/react-query-devtools": "https://pkg.csb.dev/TanStack/query/commit/df9c197e/@tanstack/react-query-devtools",

    it doesn't seem to work on my tests with the stackblitz - I get 101kb with the devtools and 87 without them.

    However, I also get 101kb if I do:

          {process.env.NODE_ENV === 'development' && (
            <ReactQueryDevtools initialIsOpen={false} />
          )}

    which, idk, should be the same as if the devtools were not there at all, right?

  6. TkDodo closed this

  7. Hi, "@tanstack/react-query": "^4.0.5", "@tanstack/react-query-devtools": "^4.0.6", CleanShot 2022-07-20 at 18 09 56

  8. @Manubi which bundler is this?

  9. Having the same issue. Devtools not loading.

  10. Can someone please provide more info?

  11. Hi again,

    "react": "18.2.0", "react-dom": "18.2.0", "next": "12.2.2", with webpack 5.

    Anything else?

  12. I face the same problem like @Manubi

Sign in to join this conversation.