Skip to content

renderComponentToString with events leaks unless component unmounted #954

Closed
@glenn-murray-bse

Description

@glenn-murray-bse

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.

var Link = React.createClass({
  leak: function(event) {

  },
  render: function() {
    return <a onClick={this.leak} >Test</a>;
  }
})

function log(str) {
  console.log(str);
}

var root = <html><body><Link /></body></html>
React.renderComponentToString(root, log);
root.unmountComponent();

renderComponentToString is API bound to be async so this sample is not future proof.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions