JedWatson / JedWatson/react-select
Memory leak in react-select
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
When using react-select, after the component is destroyed by e.g. not rendering it or more realistic example by page navigation, it leave a detached nodes that can not be garbage collected because they are not freed properly somewhere.
Link to reproduce: https://codesandbox.io/s/blissful-dream-l22yoq?file=/src/App.js
How to reproduce: https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/memory-problems/dom-leaks
Steps:
- Open https://l22yoq.csb.app/
- Open devtools -> Detached elements and click Get Detached Elements button. Observe there are no detached elements
- click on the select and choose randomly options
- click the hide button below the select to stop rendering it
- click Get Detached Elements button in the devtools
- click collect garbage button to force GC
- click Analyse button to analyse the current heap snapshot
- see there is item that is still referenced, check the last column where you have @somenumber value
Video:
https://github.com/JedWatson/react-select/assets/5074917/10a281ae-10f6-4528-b07f-7545484129e5
Expected behaviour:
When react-select is no longer rendered it should not leave detached elements, as they pile up and cause a memory leak.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction and follow the listed steps in browser DevTools, using the Detached elements view and heap snapshot analysis. Trace which react-select references remain after the component is hidden and garbage collection runs; done means unrendering the select leaves no detached elements retained.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100