Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React is needed during testing #4080

Closed
dgrcode opened this issue Aug 25, 2022 · 2 comments
Closed

React is needed during testing #4080

dgrcode opened this issue Aug 25, 2022 · 2 comments

Comments

@dgrcode
Copy link
Contributor

dgrcode commented Aug 25, 2022

Describe the bug

I'm trying to reproduce an issue in a different library (for reference issue: flightcontrolhq/superjson#196, PR: flightcontrolhq/superjson#197). For that I'm using QueryClient and dehydrate, but I'm getting the following error:

Cannot find module 'react' from 'node_modules/@tanstack/react-query/build/cjs/react-query/src/useQueries.js'

    Require stack:
      node_modules/@tanstack/react-query/build/cjs/react-query/src/useQueries.js
      node_modules/@tanstack/react-query/build/cjs/react-query/src/index.js
      src/index.test.ts

This is the whole test:

  const queryClient = new QueryClient();
  const input = { props: { dehydratedState: dehydrate(queryClient) } };

  const stringified = SuperJSON.stringify(input);
  const parsed: any = SuperJSON.parse(stringified);

  expect(parsed).toEqual(input);

Your minimal, reproducible example

https://codesandbox.io/s/tanstack-query-react-dependency-bnkx3l?file=/src/index.test.js

Steps to reproduce

  1. Go to the reproduction codesandbox
  2. Go to the tests tab
  3. The test doesn't pass

Expected behavior

I think the test should pass, since it's not using any hook, just the QueryClient and dehydrate.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • Browser: Brave
  • Version: 1.39.11

react-query version

4.2.1

TypeScript version

No response

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented Aug 26, 2022

QueryClient and dehydrate are both part of the query-core. So if you only depend on that, the test works:

https://codesandbox.io/s/tanstack-query-react-dependency-forked-x2e2v9?file=/src/index.test.js

- import { QueryClient, dehydrate } from "@tanstack/react-query";
+ import { QueryClient, dehydrate } from "@tanstack/query-core";

basically: if you depend on react-query, you need react. If you don't need react, don't depend on react-query :)

@TkDodo TkDodo closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2022
@dgrcode
Copy link
Contributor Author

dgrcode commented Aug 26, 2022

Nice! Good to know :)

This is a weird place to say this, but I'm not sure there's a good place. Thanks for being so helpful all over the place: issues (this one), discussions (#4024), PR (#4010), and even a StackOverflow Question I asked about NextJS SSR (https://stackoverflow.com/a/73342248/5452969). And those are just the places where you've helped me directly. I've definitely been helped by answers you left to other people. Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants