Skip to content

Svelte query - query does not react to changing default options by queryClient.setDefaultOptions in runtime #5855

@Pawel-Zygmunt

Description

@Pawel-Zygmunt

Describe the bug

I have initialized QueryClient in main +layout.svelte:

const queryClient = new QueryClient({ defaultOptions: { queries: { enabled: browser, refetchInterval: $dataRefetchIntervalS * 1000 } } }); $: { queryClient.setDefaultOptions({ queries: { ...queryClient.getDefaultOptions().queries, refetchInterval: $dataRefetchIntervalS * 1000 } }); } 

then, somewhere in my app on route /example i have:

const streamsQuery = createQuery({ queryKey: ['streams'], queryFn: async () => { const res = await fetch(`${PUBLIC_API_KEY}/streams`); const data = await res.json(); return data.map(streamMapper); } }); $: ({ data, status } = $streamsQuery); 

$dataRefetchIntervalS as reactive store can be changed and should cause that streamsQuery would react to a new value, but its not. StreamsQuery updates it's options only when unmounted and mounted again - while for e.g changing routes withing app.

Your minimal, reproducible example

https://stackblitz.com/edit/stackblitz-starters-megwxq?description=React%20%20%20TypeScript%20starter%20project&file=src%2Findex.tsx,src%2FApp.tsx&title=React%20Starter

Steps to reproduce

Reproducted the same behaviour in react and works fine.

Expected behavior

Queries should react to defaultOptions changed by queryClient.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: any
  • Browser: any

Tanstack Query adapter

svelte-query

TanStack Query version

5.0.0-beta.15 but also in stable version

TypeScript version

5.0.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions