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 pollInterval stop working in React v18 StrictMode #9819

Closed
pobch opened this issue Jun 14, 2022 · 28 comments · Fixed by #10629
Closed

useQuery pollInterval stop working in React v18 StrictMode #9819

pobch opened this issue Jun 14, 2022 · 28 comments · Fixed by #10629

Comments

@pobch
Copy link
Contributor

pobch commented Jun 14, 2022

Intended outcome:
pollInterval should work either with React v18 StrictMode or without StrictMode

Actual outcome:
pollInterval stop working when using it with React v18 StrictMode

How to reproduce the issue:

  1. Go to https://codesandbox.io/s/heuristic-bohr-df8gf9?file=/src/index.js
  2. Open the dev tools, go to network tab
  3. BUG: There is no new request to the graphql endpoint even though the pollingInterval is set to 2000
  4. If you remove <React.StrictMode> in index.js file, the polling will work as expected.
@cdnicoll
Copy link

+1 Seeing the same issue and confirmed that step 4 worked, but not an ideal solution

@boyerst
Copy link

boyerst commented Jun 22, 2022

Experiencing this as well. Manually triggering the poll via startPolling is a workaround

@bentron2000
Copy link

I am experiencing this as well.

@martentamm
Copy link

Same here!

@gaswirth
Copy link

gaswirth commented Aug 5, 2022

+1!

@vedmakk
Copy link

vedmakk commented Aug 30, 2022

Experiencing the same.

@Maxou44
Copy link

Maxou44 commented Oct 31, 2022

Same here 🥲

@Zonalds
Copy link

Zonalds commented Nov 1, 2022

Same here, I have to pass refetch around. Any idea if this will be fixed soon?

@thiagokpelo
Copy link

Same here too! 😢

@angelhodar
Copy link

Same, in my case its not working even if i call startPolling manually in useEffect. I have also set reactStrictMode to false in next.config.js and it doesnt solve the issue

@thiagokpelo
Copy link

If I set reactStrictMode to false in next.config.js, it works. And the workaround with startPolling and stopPolling also works.

@angelhodar
Copy link

@thiagokpelo Mmmm then i dont understand why it doesnt work in my case. I should try a minimal reproduction example. Thanks for telling me!!

@thiagokpelo
Copy link

@angelhodar will update us here if it resolves. If I can help just say! 👊

@angelhodar
Copy link

angelhodar commented Nov 2, 2022

@thiagokpelo I dont know what i am doing wrong but with a fresh nextjs project and the last version of apollo client i cant get the poll interval to work. What versions did you use to debug your nextjs project? I have tried to manually poll with startPolling and disable reactStrictMode to false and still doesnt work

@jpmermoz
Copy link

jpmermoz commented Nov 3, 2022

Same issue here. Next js with strict mode disabled and still not working

@thiagokpelo
Copy link

@angelhodar I'm using

 "dependencies": {
    "@apollo/client": "^3.7.0",
    "@chakra-ui/react": "^2.3.5",
    "@datadog/browser-logs": "^4.21.2",
    "@datadog/browser-rum": "^4.21.2",
    "@emotion/react": "^11",
    "@emotion/styled": "^11",
    "@react-oauth/google": "^0.2.8",
    "apollo-link-rest": "^0.9.0-rc.1",
    "framer-motion": "^6",
    "graphql": "^16.6.0",
    "graphql-ws": "^5.11.2",
    "next": "12.3.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-intl": "^6.1.2"
  }

Have you tried to run the built project and with npm start?

@siegfried
Copy link

siegfried commented Nov 20, 2022

Same issue here. Maybe it is dedicated to local Nextjs server yarn dev, because my app on Vercel seems fine. Manually startPolling works too.

@jurgelenas
Copy link

We are experiencing the same issue at https://github.com/ExpressLRS/ExpressLRS-Configurator

@MrDesjardins
Copy link

I had the same issue using @apollo/client:3.7.1 and this new 3.7.2 version using CRA (React version 18.0.0).

Using a timer fixed the issue temporary.

Example of the fix:

const { refetch } = useMyEntity({
    onCompleted(data) {
       // Snip
    });
   // snip
   useEffect(() => {
    const refetchQueryInterval = setInterval(() => {
      refetch();
    }, 5000;
    return () => clearInterval(refetchQueryInterval);
});

@afonsomatos
Copy link

afonsomatos commented Dec 25, 2022

I stumbled in this issue as well.
Specially with Next.JS since it enables strict mode by default (go to next.config.js and turn the flag off).

@IShinkarenko
Copy link

The same issue with Next.js 13.0.0
I set reactStrictMode to false but that does not help

@afonsomatos
Copy link

afonsomatos commented Jan 4, 2023

@IShinkarenko You probably did that but make sure you restart (shutdown and start) the Next.JS server.
Changing next.config.js won't have an effect on an ongoing instance, even if started with next dev.

@ramblehead
Copy link

Similar issue with @apollo/client@^3.7.3 and next@13.1.1 (just updated)
next start works as expected; next dev fails to start polling.

Using the following temp fix as others have suggested:

const {
  data: indexQuery,
  error: indexError,
  startPolling,
} = useQuery(IndexDocument, {
  ssr: false,
  // The following line is removed
  // pollInterval: 500,
});

// The following useEffect is added
useEffect(() => {
  startPolling(500);
}, [startPolling]);

@MarkAPhillips
Copy link

I tried version 3.7.4 but this seems to still be an issue - is they any idea as when this will be fixed ?

@mysticek
Copy link

mysticek commented Feb 27, 2023

next@13.2.1 and @apollo/client@3.7.9 , still not working, any news?
for me is not working with useQuery, useLazyQuery, with reactStrictMode: false in next.config.js - next start / next dev same result

@patrick91
Copy link

@mysticek I think this is closely related to #10540 (comment) the workaround suggested there worked for polling too (which is similar to what @ramblehead did)

Hopefully, we find a good way to fix this soon 😊

@phryneas
Copy link
Member

phryneas commented Mar 8, 2023

This is fixed in #10629 and will hopefully land in the next patch release.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2023

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 Apr 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.