Skip to content

Commit 158e0dd

Browse files
committed
Merge pull request #2614 from jsfb/monitor-should-update-owner-is-useful
Find cases where shouldUpdateReactComponent is det
2 parents 2a28189 + a463191 commit 158e0dd

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

src/core/shouldUpdateReactComponent.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
"use strict";
1414

15+
var monitorCodeUse = require('monitorCodeUse');
16+
1517
/**
1618
* Given a `prevElement` and `nextElement`, determines if the existing
1719
* instance should be updated as opposed to being destroyed or replaced by a new
@@ -30,12 +32,41 @@ function shouldUpdateReactComponent(prevElement, nextElement) {
3032
if (prevType === 'string' || prevType === 'number') {
3133
return (nextType === 'string' || nextType === 'number');
3234
} else {
33-
return (
34-
nextType === 'object' &&
35-
prevElement.type === nextElement.type &&
36-
prevElement.key === nextElement.key &&
37-
prevElement._owner === nextElement._owner
38-
);
35+
if (nextType === 'object' &&
36+
prevElement.type === nextElement.type &&
37+
prevElement.key === nextElement.key) {
38+
var ownersMatch = prevElement._owner === nextElement._owner;
39+
var prevName = null;
40+
var nextName = null;
41+
var nextDisplayName = null;
42+
if(__DEV__) {
43+
if (!ownersMatch) {
44+
if (prevElement._owner != null &&
45+
prevElement._owner.getPublicInstance() != null &&
46+
prevElement._owner.getPublicInstance().constructor != null) {
47+
prevName = prevElement._owner.getPublicInstance().constructor.displayName;
48+
}
49+
if (nextElement._owner != null &&
50+
nextElement._owner.getPublicInstance() != null &&
51+
nextElement._owner.getPublicInstance().constructor != null) {
52+
nextName = nextElement._owner.getPublicInstance().constructor.displayName;
53+
}
54+
if(nextElement.type != null && nextElement.type.displayName != null) {
55+
nextDisplayName = nextElement.type.displayName;
56+
}
57+
monitorCodeUse(
58+
'react_should_update_owner_is_useful',
59+
{
60+
key: prevElement.key,
61+
prevOwner: prevName,
62+
nextOwner: nextName,
63+
nextDisplayName: nextDisplayName
64+
}
65+
);
66+
}
67+
}
68+
return ownersMatch;
69+
}
3970
}
4071
}
4172
return false;

0 commit comments

Comments
 (0)