Skip to content

Global options mysteriously not applied #3433

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

Closed
joshribakoff-sm opened this issue Mar 23, 2022 · 2 comments
Closed

Global options mysteriously not applied #3433

joshribakoff-sm opened this issue Mar 23, 2022 · 2 comments

Comments

@joshribakoff-sm
Copy link

Describe the bug

When {suspense: true} is enabled globally, my consuming component is not suspending unless I explicitly enable it again in the useQuery() options

Your minimal, reproducible example

https://github.com/joshribakoff-sm/rq-bug/tree/no-suspense

Steps to reproduce

Wrap app in query client:

const queryClient = new QueryClient({ suspense: true });

Try to consume it and don't change any options:

  const result = useQuery(
    "foo",
    async () => {
      console.log('query ran')
      await new Promise((res) => setTimeout(res, 10000));
      return () => "foo" + Math.random();
    },
    // no suspense?
  );

Expected behavior

Component should suspend

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

macOS, chrome

react-query version

3.34.16

TypeScript version

No response

Additional context

This is not happening in my real project as far as I know, it's something I only noticed while building the reproduction repo for my previous bug report #3432

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 23, 2022

this is not a valid way to provide default options for react-query:

const queryClient = new QueryClient({ suspense: true });

Please look at the docs:

 const queryClient = new QueryClient({
   defaultOptions: {
     queries: {
       suspense: true,
     },
   },
 })

TypeScript is also good at catching these things.

@TkDodo TkDodo closed this as completed Mar 23, 2022
@joshribakoff-sm
Copy link
Author

Thanks, I am using Typescript in my main project and only used JS to produce the previous bug report, which explains:

This is not happening in my real project as far as I know, it's something I only noticed while building the reproduction repo for my previous bug report #3432

Sorry for the false report :)

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