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.

useQuery causes warning in strict mode

See original GitHub issue

When I wrap my app in <React.StrictMode />, some of my components cause the following warning:

Warning:` Can't perform a React state update on an unmounted component. This is a
no-op, but it indicates a memory leak in your application. To fix, cancel all
subscriptions and asynchronous tasks in a useEffect cleanup function.

These warning disappear outside of Strict Mode and in production builds (which turn off the StrictMode behavior). The components in question don’t set state or use useEffect. They all use useQuery however.

The warnings disappear when I remove useQuery, i.e. by replacing this:

const { data: { preference = {} } = {} } = useQuery(PREFERENCE) with an example response, like this:

const { data: { preference = {} } = {} } = {
  data: {
    preference: {
      id: 'dc1d27d7-c5fe-4de6-97c5-9db2bfaa7cd8',
      toc: false
    }
  }
}

and leaving the rest of the component unchanged.

I am using "@apollo/client": "^3.3.2" This issue was originally reposted in react-apollo repo: https://github.com/apollographql/react-apollo/issues/3635

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:23
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
brainkimcommented, Jul 11, 2021

@dchenk Can you try the beta release (npm i @apollo/client@beta)? It might be fixed on there.

4reactions
brainkimcommented, Jul 27, 2021

@DennieMello This week!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Apollo - Query - renderProp: React warning: Can't ...
I'm using "Query" from "react-apollo" and my application returns me this error. I think I am understanding the problem: my application is trying ......
Read more >
Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI. It activates...
Read more >
Upgrading to React 18 · Step-by-step guide - Felix Mokross
I assume this to be caused by the new rendering mechanism of React 18. ... const root = createRoot(container); root.render( <StrictMode> …
Read more >
urql/CHANGELOG.md - UNPKG
18, - Avoid React v16.13.0's "Warning: Cannot update a component" by ... 26, - ⚠️ Fix more concurrent-mode and strict-mode edge cases and...
Read more >
Optimistic UIs with React, Apollo Client and TypeScript (Part III)
If sending a message within a messages client causes the UI to update ... Notice how there are twenty-one messages on the optimistic...
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