Skip to content

Commit 4ba0e95

Browse files
committed
Kill ReactMount.getNode/getID/purgeID with fire
1 parent 796f8c3 commit 4ba0e95

12 files changed

+32
-549
lines changed

src/renderers/dom/client/ReactMount.js

Lines changed: 0 additions & 351 deletions
Large diffs are not rendered by default.

src/renderers/dom/client/__tests__/ReactMount-test.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -218,61 +218,6 @@ describe('ReactMount', function() {
218218
);
219219
});
220220

221-
it('should not crash in node cache when unmounting', function() {
222-
var Component = React.createClass({
223-
render: function() {
224-
// Add refs to some nodes so that they get traversed and cached
225-
return (
226-
<div ref="a">
227-
<div ref="b">b</div>
228-
{this.props.showC && <div>c</div>}
229-
</div>
230-
);
231-
},
232-
});
233-
234-
var container = document.createElement('container');
235-
236-
ReactDOM.render(<div><Component showC={false} /></div>, container);
237-
238-
// Right now, A and B are in the cache. When we add C, it won't get added to
239-
// the cache (assuming markup-string mode).
240-
ReactDOM.render(<div><Component showC={true} /></div>, container);
241-
242-
// Remove A, B, and C. Unmounting C shouldn't cause B to get recached.
243-
ReactDOM.render(<div></div>, container);
244-
245-
// Add them back -- this shouldn't cause a cached node collision.
246-
ReactDOM.render(<div><Component showC={true} /></div>, container);
247-
248-
ReactDOM.unmountComponentAtNode(container);
249-
});
250-
251-
it('should not crash in node cache when unmounting, case 2', function() {
252-
var A = React.createClass({
253-
render: function() {
254-
return <a key={this.props.innerKey}>{this.props.innerKey}</a>;
255-
},
256-
});
257-
var Component = React.createClass({
258-
render: function() {
259-
return (
260-
<b>
261-
<i>{this.props.step === 1 && <q />}</i>
262-
{this.props.step === 1 && <A innerKey={this.props.step} />}
263-
</b>
264-
);
265-
},
266-
});
267-
268-
var container = document.createElement('container');
269-
270-
ReactDOM.render(<Component step={1} />, container);
271-
ReactDOM.render(<Component step={2} />, container);
272-
ReactDOM.render(<Component step={1} />, container);
273-
ReactMount.getID(container.querySelector('a'));
274-
});
275-
276221
it('passes the correct callback context', function() {
277222
var container = document.createElement('div');
278223
var calls = 0;

src/renderers/dom/client/__tests__/ReactRenderDocument-test.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jest
1717
var React;
1818
var ReactDOM;
1919
var ReactDOMServer;
20-
var ReactInstanceMap;
21-
var ReactMount;
2220

2321
var getTestDocument;
2422

@@ -46,14 +44,12 @@ describe('rendering React components at document', function() {
4644
React = require('React');
4745
ReactDOM = require('ReactDOM');
4846
ReactDOMServer = require('ReactDOMServer');
49-
ReactInstanceMap = require('ReactInstanceMap');
50-
ReactMount = require('ReactMount');
5147
getTestDocument = require('getTestDocument');
5248

5349
testDocument = getTestDocument();
5450
});
5551

56-
it('should be able to get root component id for document node', function() {
52+
it('should be able to adopt server markup', function() {
5753
expect(testDocument).not.toBeUndefined();
5854

5955
var Root = React.createClass({
@@ -64,22 +60,24 @@ describe('rendering React components at document', function() {
6460
<title>Hello World</title>
6561
</head>
6662
<body>
67-
Hello world
63+
{'Hello ' + this.props.hello}
6864
</body>
6965
</html>
7066
);
7167
},
7268
});
7369

74-
var markup = ReactDOMServer.renderToString(<Root />);
70+
var markup = ReactDOMServer.renderToString(<Root hello="world" />);
7571
testDocument = getTestDocument(markup);
76-
var component = ReactDOM.render(<Root />, testDocument);
72+
var body = testDocument.body;
73+
74+
ReactDOM.render(<Root hello="world" />, testDocument);
7775
expect(testDocument.body.innerHTML).toBe('Hello world');
7876

79-
// TODO: This is a bad test. I have no idea what this is testing.
80-
// Node IDs is an implementation detail and not part of the public API.
81-
var componentID = ReactMount.getReactRootID(testDocument);
82-
expect(componentID).toBe(ReactInstanceMap.get(component)._rootNodeID);
77+
ReactDOM.render(<Root hello="moon" />, testDocument);
78+
expect(testDocument.body.innerHTML).toBe('Hello moon');
79+
80+
expect(body).toBe(testDocument.body);
8381
});
8482

8583
it('should not be able to unmount component from document node', function() {

src/renderers/dom/client/wrappers/ReactDOMInput.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
var DOMPropertyOperations = require('DOMPropertyOperations');
1515
var LinkedValueUtils = require('LinkedValueUtils');
1616
var ReactDOMComponentTree = require('ReactDOMComponentTree');
17-
var ReactMount = require('ReactMount');
1817
var ReactUpdates = require('ReactUpdates');
1918

2019
var assign = require('Object.assign');
@@ -189,19 +188,13 @@ function _handleChange(event) {
189188
// This will throw if radio buttons rendered by different copies of React
190189
// and the same name are rendered into the same form (same as #1939).
191190
// That's probably okay; we don't support it just as we don't support
192-
// mixing React with non-React.
193-
var otherID = ReactMount.getID(otherNode);
191+
// mixing React radio buttons with non-React ones.
192+
var otherInstance = ReactDOMComponentTree.getInstanceFromNode(otherNode);
194193
invariant(
195-
otherID,
194+
otherInstance,
196195
'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
197196
'same `name` is not supported.'
198197
);
199-
var otherInstance = instancesByReactID[otherID];
200-
invariant(
201-
otherInstance,
202-
'ReactDOMInput: Unknown radio button ID %s.',
203-
otherID
204-
);
205198
// If this is a controlled radio button group, forcing the input that
206199
// was previously checked to update will cause it to be come re-checked
207200
// as appropriate.

src/renderers/dom/shared/ReactComponentBrowserEnvironment.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
var DOMChildrenOperations = require('DOMChildrenOperations');
1515
var ReactDOMIDOperations = require('ReactDOMIDOperations');
16-
var ReactMount = require('ReactMount');
1716
var ReactPerf = require('ReactPerf');
1817

1918
/**
@@ -37,7 +36,6 @@ var ReactComponentBrowserEnvironment = {
3736
* @private
3837
*/
3938
unmountIDFromEnvironment: function(rootNodeID) {
40-
ReactMount.purgeID(rootNodeID);
4139
},
4240

4341
};

src/renderers/dom/shared/ReactDOMComponent.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var ReactDOMInput = require('ReactDOMInput');
3333
var ReactDOMOption = require('ReactDOMOption');
3434
var ReactDOMSelect = require('ReactDOMSelect');
3535
var ReactDOMTextarea = require('ReactDOMTextarea');
36-
var ReactMount = require('ReactMount');
3736
var ReactMultiChild = require('ReactMultiChild');
3837
var ReactPerf = require('ReactPerf');
3938
var ReactUpdateQueue = require('ReactUpdateQueue');
@@ -662,8 +661,6 @@ ReactDOMComponent.Mixin = {
662661
ReactDOMComponentTree.precacheNode(this, el);
663662
this._flags |= Flags.hasCachedChildNodes;
664663
DOMPropertyOperations.setAttributeForID(el, this._rootNodeID);
665-
// Populate node cache
666-
ReactMount.getID(el);
667664
this._updateDOMProperties(null, props, transaction);
668665
var lazyTree = DOMLazyTree(el);
669666
this._createInitialChildren(transaction, props, context, lazyTree);

src/renderers/dom/shared/ReactDOMTextComponent.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var DOMPropertyOperations = require('DOMPropertyOperations');
1818
var ReactComponentBrowserEnvironment =
1919
require('ReactComponentBrowserEnvironment');
2020
var ReactDOMComponentTree = require('ReactDOMComponentTree');
21-
var ReactMount = require('ReactMount');
2221

2322
var assign = require('Object.assign');
2423
var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
@@ -99,10 +98,8 @@ assign(ReactDOMTextComponent.prototype, {
9998
if (transaction.useCreateElement) {
10099
var ownerDocument = nativeContainerInfo._ownerDocument;
101100
var el = ownerDocument.createElement('span');
102-
this._nativeNode = el;
101+
ReactDOMComponentTree.precacheNode(this, el);
103102
DOMPropertyOperations.setAttributeForID(el, rootID);
104-
// Populate node cache
105-
ReactMount.getID(el);
106103
var lazyTree = DOMLazyTree(el);
107104
DOMLazyTree.queueText(lazyTree, this._stringText);
108105
return lazyTree;

src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var MorphingComponent;
1616
var React;
1717
var ReactDOM;
1818
var ReactCurrentOwner;
19-
var ReactMount;
2019
var ReactPropTypes;
2120
var ReactServerRendering;
2221
var ReactTestUtils;
@@ -34,7 +33,6 @@ describe('ReactCompositeComponent', function() {
3433
ReactCurrentOwner = require('ReactCurrentOwner');
3534
ReactPropTypes = require('ReactPropTypes');
3635
ReactTestUtils = require('ReactTestUtils');
37-
ReactMount = require('ReactMount');
3836
ReactServerRendering = require('ReactServerRendering');
3937
ReactUpdates = require('ReactUpdates');
4038

@@ -487,8 +485,6 @@ describe('ReactCompositeComponent', function() {
487485
var container = document.createElement('div');
488486
var innerUnmounted = false;
489487

490-
spyOn(ReactMount, 'purgeID').andCallThrough();
491-
492488
var Component = React.createClass({
493489
render: function() {
494490
return (
@@ -501,11 +497,6 @@ describe('ReactCompositeComponent', function() {
501497
});
502498
var Inner = React.createClass({
503499
componentWillUnmount: function() {
504-
// It's important that ReactMount.purgeID is called after any component
505-
// lifecycle methods, because a componentWillUnmount implementation is
506-
// likely to call ReactDOM.findDOMNode(this), which will repopulate the
507-
// node cache after it's been cleared, causing a memory leak.
508-
expect(ReactMount.purgeID.calls.length).toBe(0);
509500
innerUnmounted = true;
510501
},
511502
render: function() {
@@ -516,12 +507,6 @@ describe('ReactCompositeComponent', function() {
516507
ReactDOM.render(<Component />, container);
517508
ReactDOM.unmountComponentAtNode(container);
518509
expect(innerUnmounted).toBe(true);
519-
520-
// The text and both <div /> elements and their wrappers each call
521-
// unmountIDFromEnvironment which calls purgeID, for a total of 3.
522-
// TODO: Test the effect of this. E.g. does the node cache get repopulated
523-
// after a getDOMNode call?
524-
expect(ReactMount.purgeID.calls.length).toBe(3);
525510
});
526511

527512
it('should warn when shouldComponentUpdate() returns undefined', function() {

src/renderers/shared/reconciler/__tests__/ReactIdentity-test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@
1313

1414
var React;
1515
var ReactDOM;
16+
var ReactDOMComponentTree;
1617
var ReactFragment;
1718
var ReactTestUtils;
18-
var ReactMount;
1919

2020
describe('ReactIdentity', function() {
2121

2222
beforeEach(function() {
2323
jest.resetModuleRegistry();
2424
React = require('React');
2525
ReactDOM = require('ReactDOM');
26+
ReactDOMComponentTree = require('ReactDOMComponentTree');
2627
ReactFragment = require('ReactFragment');
2728
ReactTestUtils = require('ReactTestUtils');
28-
ReactMount = require('ReactMount');
2929
});
3030

3131
var idExp = /^\.[^.]+(.*)$/;
3232
function checkID(child, expectedID) {
33-
var actual = idExp.exec(ReactMount.getID(child));
33+
// TODO: Node IDs are not public API; rewrite these tests.
34+
var rootID = ReactDOMComponentTree.getInstanceFromNode(child)._rootNodeID;
35+
var actual = idExp.exec(rootID);
3436
var expected = idExp.exec(expectedID);
3537
expect(actual).toBeTruthy();
3638
expect(expected).toBeTruthy();
@@ -297,14 +299,16 @@ describe('ReactIdentity', function() {
297299
var wrapped = <TestContainer first={instance0} second={instance1} />;
298300

299301
wrapped = ReactDOM.render(wrapped, document.createElement('div'));
302+
var div = ReactDOM.findDOMNode(wrapped);
300303

301-
var beforeID = ReactMount.getID(ReactDOM.findDOMNode(wrapped).firstChild);
302-
304+
var beforeA = div.childNodes[0];
305+
var beforeB = div.childNodes[1];
303306
wrapped.swap();
307+
var afterA = div.childNodes[1];
308+
var afterB = div.childNodes[0];
304309

305-
var afterID = ReactMount.getID(ReactDOM.findDOMNode(wrapped).firstChild);
306-
307-
expect(beforeID).not.toEqual(afterID);
310+
expect(beforeA).toBe(afterA);
311+
expect(beforeB).toBe(afterB);
308312

309313
});
310314

0 commit comments

Comments
 (0)