Skip to content
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

Refactor how composite type changes work, fix memory leak in ReactMount caching #4983

Merged
merged 5 commits into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use returned native node for composite type-change
With this change, all unmounted components should be properly purged from ReactMount's cache.
  • Loading branch information
sophiebits committed Oct 7, 2015
commit 60491d89f88a04a6be29a52b652090ba276ba7a9
14 changes: 0 additions & 14 deletions src/renderers/dom/client/ReactDOMIDOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ var ReactDOMIDOperations = {
}
},

/**
* Replaces a DOM node that exists in the document with markup.
*
* @param {string} id ID of child to be replaced.
* @param {string} markup Dangerous markup to inject in place of child.
* @internal
* @see {Danger.dangerouslyReplaceNodeWithMarkup}
*/
dangerouslyReplaceNodeWithMarkupByID: function(id, markup) {
var node = ReactMount.getNode(id);
DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup(node, markup);
},

/**
* Updates a component's children by processing a series of updates.
*
Expand All @@ -92,7 +79,6 @@ var ReactDOMIDOperations = {
};

ReactPerf.measureMethods(ReactDOMIDOperations, 'ReactDOMIDOperations', {
dangerouslyReplaceNodeWithMarkupByID: 'dangerouslyReplaceNodeWithMarkupByID',
dangerouslyProcessChildrenUpdates: 'dangerouslyProcessChildrenUpdates',
});

Expand Down
14 changes: 12 additions & 2 deletions src/renderers/dom/shared/ReactComponentBrowserEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

'use strict';

var DOMChildrenOperations = require('DOMChildrenOperations');
var ReactDOMIDOperations = require('ReactDOMIDOperations');
var ReactMount = require('ReactMount');
var ReactPerf = require('ReactPerf');

/**
* Abstracts away all functionality of the reconciler that requires knowledge of
Expand All @@ -24,8 +26,8 @@ var ReactComponentBrowserEnvironment = {
processChildrenUpdates:
ReactDOMIDOperations.dangerouslyProcessChildrenUpdates,

replaceNodeWithMarkupByID:
ReactDOMIDOperations.dangerouslyReplaceNodeWithMarkupByID,
replaceNodeWithMarkup:
DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup,

/**
* If a particular environment requires that some resources be cleaned up,
Expand All @@ -40,4 +42,12 @@ var ReactComponentBrowserEnvironment = {

};

ReactPerf.measureMethods(
ReactComponentBrowserEnvironment,
'ReactComponentBrowserEnvironment',
{
replaceNodeWithMarkup: 'replaceNodeWithMarkup',
}
);

module.exports = ReactComponentBrowserEnvironment;
6 changes: 3 additions & 3 deletions src/renderers/shared/reconciler/ReactComponentEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var ReactComponentEnvironment = {
* Optionally injectable hook for swapping out mount images in the middle of
* the tree.
*/
replaceNodeWithMarkupByID: null,
replaceNodeWithMarkup: null,

/**
* Optionally injectable hook for processing a queue of child updates. Will
Expand All @@ -44,8 +44,8 @@ var ReactComponentEnvironment = {
);
ReactComponentEnvironment.unmountIDFromEnvironment =
environment.unmountIDFromEnvironment;
ReactComponentEnvironment.replaceNodeWithMarkupByID =
environment.replaceNodeWithMarkupByID;
ReactComponentEnvironment.replaceNodeWithMarkup =
environment.replaceNodeWithMarkup;
ReactComponentEnvironment.processChildrenUpdates =
environment.processChildrenUpdates;
injected = true;
Expand Down
18 changes: 9 additions & 9 deletions src/renderers/shared/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,30 +729,30 @@ var ReactCompositeComponentMixin = {
this._processChildContext(context)
);
} else {
// These two IDs are actually the same! But nothing should rely on that.
var thisID = this._rootNodeID;
var prevComponentID = prevComponentInstance._rootNodeID;
ReactReconciler.unmountComponent(prevComponentInstance);
var oldNativeNode =
ReactReconciler.unmountComponent(prevComponentInstance);

this._renderedComponent = this._instantiateReactComponent(
nextRenderedElement
);
var nextMarkup = ReactReconciler.mountComponent(
this._renderedComponent,
thisID,
this._rootNodeID,
transaction,
this._processChildContext(context)
);
this._replaceNodeWithMarkupByID(prevComponentID, nextMarkup);
this._replaceNodeWithMarkup(oldNativeNode, nextMarkup);
}
},

/**
* Overridden in shallow rendering.
*
* @protected
*/
_replaceNodeWithMarkupByID: function(prevComponentID, nextMarkup) {
ReactComponentEnvironment.replaceNodeWithMarkupByID(
prevComponentID,
_replaceNodeWithMarkup: function(oldNativeNode, nextMarkup) {
ReactComponentEnvironment.replaceNodeWithMarkup(
oldNativeNode,
nextMarkup
);
},
Expand Down
3 changes: 2 additions & 1 deletion src/test/ReactDefaultPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ var ReactDefaultPerf = {
moduleName === 'ReactDOMIDOperations' ||
moduleName === 'CSSPropertyOperations' ||
moduleName === 'DOMChildrenOperations' ||
moduleName === 'DOMPropertyOperations') {
moduleName === 'DOMPropertyOperations' ||
moduleName === 'ReactComponentBrowserEnvironment') {
start = performanceNow();
rv = func.apply(this, args);
totalTime = performanceNow() - start;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ assign(
_instantiateReactComponent: function(element) {
return new NoopInternalComponent(element);
},
_replaceNodeWithMarkupByID: function() {},
_replaceNodeWithMarkup: function() {},
_renderValidatedComponent:
ReactCompositeComponent.Mixin
._renderValidatedComponentWithoutOwnerOrContext,
Expand Down