-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
renderComponentToString with events leaks unless component unmounted #954
Comments
So Btw perhaps some day |
renderComponentToString registers events. If the calling code does not unmount the component or unregister the listeners this will leak memory. Passing this test should fix this.
Flag on EventPluginHub to disable event registration. For the purposes of server side rendering not registering events. Could be cleaner if used a transaction with an optional step. Alternatively could be an ExecutionEnvironment variable. Could also be flag passed to mount component, however non DOM components have no comprehension of events.
EventPluginHub.setRegistrationEnabled(boolean) will toggle whether putListener will register event listeners.
Given that (for my use case) renderComponentToString should not register listeners, I created a failing test case d422ebd, a fix 0b5ad13 and test coverage for the fix 8dbeb85 The exposed changes are:
Calls to |
The negative case test case d422ebd from the closed pull request may still be useful. |
@glenn-murray-bse thanks! would love to find a way to automate the workflow you're using and put it on CI. |
My current workflow involves a GUI (the chrome dev tools) so would be difficult to codify. There are programatic heap dumpers for node (eg https://github.com/bnoordhuis/node-heapdump, https://github.com/davepacheco/node-heap-dump), but none I could find which automate comparisons between heap snapshots. Either of those modules would probably provide a good place to start. |
Cool I'll take a look. I'm experimenting with automated tooling around this kind of stuff (#620) so if anyone comes up with any ideas be sure to let me know :) |
Repeated calls to renderComponentToString with evented components (i.e. onClick={this.handleClick}) will effectively leak memory.
Call unmountComponent on rendered components lest event listening closures remain non-garbage collected.
Only long lived processes with repeated render calls will notice.
http://jsfiddle.net/tS8Nv/1/
Adding component.unmountComponent() at ReactServerRendering.js:54 would fix this, but would break tests which render react root document nodes with an Invariant Violation.
renderComponentToString is API bound to be async so this sample is not future proof.
The text was updated successfully, but these errors were encountered: