vue-query-nuxt icon indicating copy to clipboard operation
vue-query-nuxt copied to clipboard

retry in defaultOptions for queryClient doesn't work

Open Demetri0 opened this issue 11 months ago • 1 comments

Environment

"@hebilicious/vue-query-nuxt": "^0.3.0"

Reproduction

https://codesandbox.io/p/devbox/4pq98t

Describe the bug

I'm trying to setup retry globally through nuxt.config.ts, but it doesn't work.

I made a simple example in a codesendbox, so you can see how I'm doing.

Open Chrome DevTools on the page. There you can see that it trying to retry (4 times) '/api/fail' (fake handler made through /server/api/fail.js - just throws an error).

But in the nuxt.config.ts I've set retry function with return failureCount < 1; so it shouldn't retry. Also there is console.log but we cannot see it in a console.

image

https://codesandbox.io/p/devbox/4pq98t

Maybe I'm doing something wrong?

Additional context

No response

Logs

No response

Demetri0 avatar Dec 30 '24 01:12 Demetri0

Hello, because the Nuxt design https://nuxt.com/docs/guide/going-further/runtime-config#serialization we cannot use non-serializable (Infinity, NaN, function... ) value in nuxt.config.ts

use the vue-query.config.ts way, e.g. https://nuxt.com/modules/vue-query#_4-advanced-configuration

export default defineVueQueryPluginHook(({ queryClient }) => {
  // here, set the default options
  queryClient.setDefaultOptions({
    queries: { staleTime: Infinity },
  });
  return {
    pluginReturn: { provide: { } }, // nuxt plugin return value
    vueQueryPluginOptions: { queryClient }, // You can pass dynamic options
  };
});

zvn2060 avatar May 03 '25 13:05 zvn2060

Thank you for answer 👍

Demetri0 avatar May 08 '25 14:05 Demetri0