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.

Memory leak when using apollo-client in an iframe.

See original GitHub issue

Hello,

It seems that closing an iframe, while Apollo is loading a request inside, together with user interaction, is causing the iframe to crush. Sounds niche, but my app is heavily reliant on iframes to operate and separate user code from our main site.

Some hints I found trying to debug it:

  • It happens only in Chrome. (which most our users have)
  • Happens in standalone projects and different GQL servers.
  • It does not happen if I implement the request with fetch and useState() instead of @apollo/client
  • It only happens together with user interaction.
  • It happens less in “production” mode. (Might be preventable by some Webpack optimization?)

Intended outcome: Apollo client should gracefully shut itself down and free resources when closing. (maybe using the window onunload event)

Actual outcome: Chrome freezes. 😦 No errors are emitted to the log.

Screen Shot 2021-02-04 at 20 21 02

How to reproduce the issue: I managed to reproduce the bug using the code in this gist: https://gist.github.com/KutnerUri/5b65a2893c30a40646fe99726847a072 Paste it in a create-react-app to reproduce it yourself. (I used React 16)

Kapture 2021-02-04 at 20 24 53

Does not happen using fetch and react state: Kapture 2021-02-04 at 20 28 45

I could not make a live website using CodeSandbox, as it didn’t allow iframes.

Versions

  @apollo/client:  3.3.6
  react: 16.13.1
  react-dom: 16.13.1

  System:
    OS: macOS 11.1
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.19.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v12.19.0/bin/npm
  Browsers:
    Chrome: 88.0.4324.146
    Edge: 88.0.705.56
    Firefox: 84.0.2
    Safari: 14.0.2

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KutnerUricommented, Jun 13, 2021

yes - copy this to a CRA’s app.js, and click on toggle repeatedly. https://gist.github.com/KutnerUri/5b65a2893c30a40646fe99726847a072

Make sure to use React16.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak when a iframe with url pointing to a react app is ...
I have a react-redux app which runs inside iframe, Iframe with same exact url is getting removed and added back by the parent...
Read more >
Migrating to Apollo Client 3.0 - Apollo GraphQL Docs
This article walks you through migrating your application to Apollo Client 3.0 from previous versions of Apollo Client. To illustrate the migration process, ......
Read more >
[React +GraphQL] Using refetchQuery causes memory leaks?
This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the ......
Read more >
Clustering 4000 Stack Overflow tags with BigQuery k-means
You can check out more about working with Stack Overflow data and ... memory-management, compilation, memory-leaks, operating-system, io, ...
Read more >
top5relatedtags - Stack Exchange Data Explorer
... 'jsf-2', 'oauth', 'memory-leaks', 'visual-studio-2008', 'fonts', ... 'ibm-mobilefirst', 'out-of-memory', 'ssl-certificate', 'java-me', ...
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