question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `refetchOnWindowFocus` when I change it to false it fetches one more time!

See original GitHub issue

I’m using this code to query my players:

export let refetchEnabled: boolean;

$: players = useQuery("/players",
  async () => await getPlayers(),
  { refetchOnWindowFocus: refetchEnabled }
);

but in this way when I switch refetchEnabled to false it refetches my players one more time before stopping.

Am I wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
frederikhorscommented, Aug 15, 2021

if you want to change the query key then you do have to actually recreate the whole query object

@amen-souissi can you please help here? Svelte newbie here. 😄

@amen-souissi are you still interested in keeping the project and helping people use it? I sincerely ask just to understand for the future, no criticism between the lines… 😃

1reaction
dimfeldcommented, Aug 4, 2021

The is no mention in docs about: updateOptions(), or am I wrong?

Not that I’ve seen. I just found it in the source a while ago when I was looking for similar functionality.

You said for your code:

it avoids recreating the entire query when refetchEnabled changes

Is this a performance problem?

Not really, but my supposition was that recreating the query is causing it to run the fetch again when you didn’t want it to.

As for the other questions, I think if you want to change the query key then you do have to actually recreate the whole query object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useQuery `refetchOnWindowFocus` option does not respect ...
Queries are fetched unnecessary even when retry is set to false , retryCount resets every time on window focus.
Read more >
Window Focus Refetching | TanStack Query Docs
If a user leaves your application and returns to stale data, React Query automatically requests fresh data for you in the background.
Read more >
React Query - refetch on window focus but not otherwise?
If i change the staleTime to Infinity like suggested in the question above, React Query would never refetch on window focus.
Read more >
Fetch a query only once until page refresh using React Query
The network is reconnected. We turned off most of the library defaults because it's okay for the data we're displaying to be stale...
Read more >
Window Focus Refetching | Svelte Query | SvelteStack
Window Focus Refetching. If a user leaves your application and returns to stale data, Svelte Query automatically requests fresh data for you in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found