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

useQuery polling query does not stop issuing network requests when the skip argument switches from false to true #12046

Closed
andreimatei opened this issue Aug 30, 2024 · 4 comments

Comments

@andreimatei
Copy link

andreimatei commented Aug 30, 2024

Issue Description

Consider the following code:

export const AgentReportsProvider: React.FunctionComponent<
  PropsWithChildren<unknown>
> = ({children}) => {
  // If authentication is enabled but there is no logged-in user, skip the
  // query.
  let skip = false;
  if (appCfg.AuthEnabled && !appCfg.User) {
    skip = true;
  }
  const {data: reportRes} = useQuery(GET_AGENT_REPORTS, {
    pollInterval: appCfg.AgentsPollIntervalMillis,
    fetchPolicy: "no-cache",
    skip: skip,
  });

...

The intention is to poll this query while the user is logged in, and stop polling it when the user logs out. This doesn't seem to work: if skip is ever false, network requests continue to be issued even after skip turns to true later.

Note that all I see are the network requests still being issued. I don't know if the component re-renders with new results from the query.

I have also tried switching the pollInterval argument to undefined once skip is set to true; it did not help.

A few months ago I had found a perhaps similar bug with useSuspenseQuery (#11768), in case that provides inspiration.

Link to Reproduction

N/A

Reproduction Steps

No response

@apollo/client version

3.9.11, 3.11.5

@andreimatei andreimatei changed the title useQuery polling query does not stop issuing network requests when the skip argument switches from true to false useQuery polling query does not stop issuing network requests when the skip argument switches from false to true Sep 16, 2024
@andreimatei
Copy link
Author

I had typed this issue backwards, claiming that the problem is when switching skip from true -> false. It's the other way around -- the problem is when switch false -> true. I've edited the post above to make it sane.


I have also tried switching the pollInterval argument to undefined once skip is set to true; it did not help.

Setting pollInterval to a really high number does help, though, fwiw.

@andreimatei
Copy link
Author

Closing as a duplicate of #11120

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant