@@ -99,7 +99,7 @@ function getReactRootElementInContainer(container) {
99
99
*/
100
100
function getReactRootID ( container ) {
101
101
var rootElement = getReactRootElementInContainer ( container ) ;
102
- return rootElement && ReactMount . getID ( rootElement ) ;
102
+ return rootElement && internalGetID ( rootElement ) ;
103
103
}
104
104
105
105
/**
@@ -115,20 +115,12 @@ function getReactRootID(container) {
115
115
function getID ( node ) {
116
116
var id = internalGetID ( node ) ;
117
117
if ( id ) {
118
- if ( nodeCache . hasOwnProperty ( id ) ) {
119
- var cached = nodeCache [ id ] ;
120
- if ( cached !== node ) {
121
- invariant (
122
- ! isValid ( cached , id ) ,
123
- 'ReactMount: Two valid but unequal nodes with the same `%s`: %s' ,
124
- ATTR_NAME , id
125
- ) ;
126
-
127
- nodeCache [ id ] = node ;
128
- }
129
- } else {
130
- nodeCache [ id ] = node ;
131
- }
118
+ invariant (
119
+ ! nodeCache . hasOwnProperty ( id ) || nodeCache [ id ] === node ,
120
+ 'ReactMount: Two unequal nodes with the same `%s`: %s' ,
121
+ ATTR_NAME , id
122
+ ) ;
123
+ nodeCache [ id ] = node ;
132
124
}
133
125
134
126
return id ;
@@ -156,6 +148,25 @@ function setID(node, id) {
156
148
nodeCache [ id ] = node ;
157
149
}
158
150
151
+ /**
152
+ * Finds the node with the supplied ID if present in the cache.
153
+ */
154
+ function getNodeIfCached ( id ) {
155
+ var node = nodeCache [ id ] ;
156
+ // TODO: Since this "isValid" business is now just a sanity check, we can
157
+ // probably drop it with no consequences.
158
+ invariant (
159
+ ! node || isValid ( node , id ) ,
160
+ 'ReactMount: Cached node with `%s`: %s is missing from the document. ' +
161
+ 'This probably means the DOM was unexpectedly mutated -- when removing ' +
162
+ 'React-rendered children from the DOM, rerender without those children ' +
163
+ 'or call ReactDOM.unmountComponentAtNode on the container to unmount an ' +
164
+ 'entire subtree.' ,
165
+ ATTR_NAME , id
166
+ ) ;
167
+ return node ;
168
+ }
169
+
159
170
/**
160
171
* Finds the node with the supplied React-generated DOM ID.
161
172
*
@@ -164,10 +175,11 @@ function setID(node, id) {
164
175
* @internal
165
176
*/
166
177
function getNode ( id ) {
167
- if ( ! nodeCache . hasOwnProperty ( id ) || ! isValid ( nodeCache [ id ] , id ) ) {
168
- nodeCache [ id ] = ReactMount . findReactNodeByID ( id ) ;
178
+ if ( nodeCache . hasOwnProperty ( id ) ) {
179
+ return getNodeIfCached ( id ) ;
180
+ } else {
181
+ return nodeCache [ id ] = ReactMount . findReactNodeByID ( id ) ;
169
182
}
170
- return nodeCache [ id ] ;
171
183
}
172
184
173
185
/**
@@ -182,10 +194,7 @@ function getNodeFromInstance(instance) {
182
194
if ( ReactEmptyComponentRegistry . isNullComponentID ( id ) ) {
183
195
return null ;
184
196
}
185
- if ( ! nodeCache . hasOwnProperty ( id ) || ! isValid ( nodeCache [ id ] , id ) ) {
186
- nodeCache [ id ] = ReactMount . findReactNodeByID ( id ) ;
187
- }
188
- return nodeCache [ id ] ;
197
+ return getNode ( id ) ;
189
198
}
190
199
191
200
/**
@@ -226,8 +235,8 @@ function purgeID(id) {
226
235
227
236
var deepestNodeSoFar = null ;
228
237
function findDeepestCachedAncestorImpl ( ancestorID ) {
229
- var ancestor = nodeCache [ ancestorID ] ;
230
- if ( ancestor && isValid ( ancestor , ancestorID ) ) {
238
+ var ancestor = getNodeIfCached ( ancestorID ) ;
239
+ if ( ancestor ) {
231
240
deepestNodeSoFar = ancestor ;
232
241
} else {
233
242
// This node isn't populated in the cache, so presumably none of its
0 commit comments