stratiformltd / react-loadable-visibility

A wrapper around react-loadable and @loadable/component to load elements once they are visible on the page.
BSD 3-Clause "New" or "Revised" License
1.01k stars 31 forks source link

Fix memory leak when using server-side #11

Closed the83 closed 6 years ago

the83 commented 6 years ago

I recently ran into a memory leak when using this server-side. This occurs because the visibility handlers are set up in the constructor instead of a lifecycle hook, and because componentWillUnmount does not execute server-side, we never stop observing the element. I set up a simple example of this happening here: https://github.com/the83/memory-leak-example

This moves the setup into the componentDidMount hook so that we don't even observe visibility at all server-side.

tazsingh commented 6 years ago

Released under 2.5.0 - https://github.com/stratiformltd/react-loadable-visibility/releases/tag/v2.5.0 Thanks!