Skip to content

Feature/1936 no queryclient set in devtools - #2113

Merged
TkDodo merged 7 commits into
TanStack:masterfrom
TkDodo:feature/1936-no-queryclient-set-in-devtools
Apr 13, 2021
Merged

TkDodo merged 7 commits into
TanStack:masterfrom
TkDodo:feature/1936-no-queryclient-set-in-devtools

Conversation

@TkDodo

@TkDodo TkDodo commented Apr 12, 2021 •

Copy link
Copy Markdown
Collaborator

closes #1936

@vercel

vercel Bot commented Apr 12, 2021 •

Copy link
Copy Markdown

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/66ZNovxjNgrVnQKVXS6mQwJ4zVeD
✅ Preview: https://react-query-git-fork-tkdodo-feature-1936-no-queryclie-fe3c87.vercel.app

@codesandbox-ci

codesandbox-ci Bot commented Apr 12, 2021 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1e18f1c:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

@Ephem

Ephem commented Apr 12, 2021

Copy link
Copy Markdown
Collaborator

Nice!

I have no idea if there is any extra build config that is needed to support this as well. When I went back to my original PR for hydration, I saw there was some external and globals-config stuff in the rollup config that might be relevant.

I haven't checked if that's the case, but might be worth double checking if this PR doesn't bundle the entire react-query into the devtools package. 😄

@TkDodo

TkDodo commented Apr 13, 2021

Copy link
Copy Markdown
Collaborator Author

so I downloaded: https://pkg.csb.dev/tannerlinsley/react-query/commit/6a704898/react-query

and it doesn't look like the devtools package contains a copy of react-query - it is also the same size as before.

The rollup config changed significantly with v3 and there is now no globals-config anymore

do you think we can merge this? Is the eslint-disable acceptable?

@Ephem

Ephem commented Apr 13, 2021

Copy link
Copy Markdown
Collaborator

That's good! This warning when building doesn't look great though:

image

According to this article (now pretty old) Rollup tries to add external and globals for you automatically for unresolved dependencies, but prints a warning. In this case, it seems as if it's guessing the wrong name for the global name though (reactQuery instead of ReactQuery). I think this means this PR can break in some cases (when loading React Query/devtools from a CDN?).

Since it's a one line change and needs the exact same fixes, maybe you'd like to fix the relative import in the hydration package in this PR as well? In that case, I could verify that it works, otherwise I'll open a separate PR for that. 😄

@Ephem

Ephem commented Apr 13, 2021

Copy link
Copy Markdown
Collaborator

I think maybe a rollup config like this would work and be flexible to fix the relative imports that exists in other packages as well?

import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import size from 'rollup-plugin-size'
import externalDeps from 'rollup-plugin-peer-deps-external'
import resolve from 'rollup-plugin-node-resolve'
import commonJS from 'rollup-plugin-commonjs'
import visualizer from 'rollup-plugin-visualizer'
import replace from '@rollup/plugin-replace'

const inputSrcs = [
  ['src/index.ts', 'ReactQuery', 'react-query'],
  ['src/core/index.ts', 'ReactQueryCore', 'react-query-core'],
  [
    'src/devtools/index.ts',
    'ReactQueryDevtools',
    'react-query-devtools',
    {
      extraExternals: ['react-query'],
      extraGlobals: { 'react-query': 'ReactQuery' },
    },
  ],
  [
    'src/hydration/index.ts',
    'ReactQueryHydration',
    'react-query-hydration',
    {
      extraExternals: ['react-query'],
      extraGlobals: { 'react-query': 'ReactQuery' },
    },
  ],
  [
    'src/persistQueryClient-experimental/index.ts',
    'ReactQueryPersistQueryClientExperimental',
    'persistQueryClient-experimental',
  ],
  [
    'src/createLocalStoragePersistor-experimental/index.ts',
    'ReactQueryCreateLocalStoragePersistorExperimental',
    'createLocalStoragePersistor-experimental',
  ],
  [
    'src/broadcastQueryClient-experimental/index.ts',
    'ReactQueryBroadcastQueryClientExperimental',
    'broadcastQueryClient-experimental',
  ],
]

const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx']
const babelConfig = { extensions, runtimeHelpers: true }
const resolveConfig = { extensions }

export default inputSrcs
  .map(
    ([input, name, file, { extraExternals = [], extraGlobals = {} } = {}]) => {
      const external = ['react', 'react-dom', ...extraExternals]

      const globals = {
        react: 'React',
        'react-dom': 'ReactDOM',
        ...extraGlobals,
      }

      return [
        {
          input: input,
          output: {
            name,
            file: `dist/${file}.development.js`,
            format: 'umd',
            sourcemap: true,
            globals,
          },
          external,
          plugins: [
            resolve(resolveConfig),
            babel(babelConfig),
            commonJS(),
            externalDeps(),
          ],
        },
        {
          input: input,
          output: {
            name,
            file: `dist/${file}.production.min.js`,
            format: 'umd',
            sourcemap: true,
            globals,
          },
          external,
          plugins: [
            replace({
              'process.env.NODE_ENV': `"production"`,
              delimiters: ['', ''],
            }),
            resolve(resolveConfig),
            babel(babelConfig),
            commonJS(),
            externalDeps(),
            terser(),
            size(),
            visualizer({
              filename: 'stats-react.json',
              json: true,
            }),
          ],
        },
      ]
    }
  )
  .flat()

TkDodo added 2 commits April 13, 2021 20:17
eslint-allow that the devtools import from react-query even though react-query is not a direct dependency
try to silence the rollup build warnings about react-query not found when building the devtools
@TkDodo

TkDodo commented Apr 13, 2021

Copy link
Copy Markdown
Collaborator Author

Since it's a one line change and needs the exact same fixes, maybe you'd like to fix the relative import in the hydration package in this PR as well? In that case, I could verify that it works, otherwise I'll open a separate PR for that. 😄

let's do a separate PR as a follow up please. from what I can see, hydration imports multiple things relatively ...

@Ephem

Ephem commented Apr 13, 2021

Copy link
Copy Markdown
Collaborator

Since it's a one line change and needs the exact same fixes, maybe you'd like to fix the relative import in the hydration package in this PR as well? In that case, I could verify that it works, otherwise I'll open a separate PR for that. 😄

let's do a separate PR as a follow up please. from what I can see, hydration imports multiple things relatively ...

Of course! I'll take care of that tomorrow. 😄

@Ephem Ephem left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not familiar enough with the devtools to verify the fix itself but saw that was done in the issue, this looks good to me! 💯

Comment thread .eslintrc Outdated
{
"files": ["src/devtools/**/*.{ts,tsx}"],
"rules": {
"import/no-unresolved": ["error", { "ignore": ["react-query"] }]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NIT: Since we added react-query as an external and global for all entry points, I think it makes sense to configure this ignore to be global instead of a devtools-specific override as well? I definitely don't have strong feelings on it though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I just thought that maybe it's a good idea to avoid wrong auto-imports or so, but being in line with the rollup config is also valuable: 7398b24

uff, and the missing comma 🤦
1e18f1c

eslint-allow import from react-query everywhere to be aligned with the rollup config
@TkDodo
TkDodo merged commit eac52f6 into TanStack:master Apr 13, 2021
@TkDodo
TkDodo deleted the feature/1936-no-queryclient-set-in-devtools branch April 13, 2021 20:11
@tannerlinsley

Copy link
Copy Markdown
Member

🎉 This PR is included in version 3.13.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

This branch was successfully deployed

1 active deployment
Preview — 1e18f1ca Deployed Apr 13, 2021 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"No QueryClient set" when upgrading from 3.12.0 to 3.12.1

3 participants