Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit f67b556

Browse files
committed
check for renderer's id in isReactDOM
1 parent 12e62b4 commit f67b556

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

backend/installGlobalHook.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ function installGlobalHook(window: Object) {
142142
return 'production';
143143
}
144144
function isReactDOM(renderer) {
145+
if (renderer.id === 'react-dom') {
146+
return true;
147+
}
148+
// Try to detect old versions without id injected
145149
try {
146150
var toString = Function.prototype.toString;
147151
if (typeof renderer.version === 'string') {
@@ -154,29 +158,29 @@ function installGlobalHook(window: Object) {
154158
renderer.Mount._renderNewRootComponent
155159
);
156160

157-
// Check for React DOM 15.*
161+
// React DOM 15.*
158162
if (
159163
renderRootCode.indexOf('ensureScrollValueMonitoring') !== -1 &&
160164
renderRootCode.indexOf('37') !== -1
161165
) {
162166
return true;
163167
}
164-
// Check for React DOM Stack 0.13.*/0.14.*
168+
// React DOM Stack 0.13.*/0.14.*
165169
if (renderRootCode.indexOf('_registerComponent') !== -1) {
166170
return true;
167171
}
168-
// It's something we aren't aware of => not ReactDOM
172+
// Something we're not aware of => not ReactDOM
169173
return false;
170174
}
171175
} catch (err) {
172-
// TODO: Mirrors error handling of detectDuplicatedReact()
176+
// TODO: Mirrors error handling of detectReactBuildType()
173177
}
174178
return false;
175179
}
176180
function detectDuplicatedReact(renderers) {
177181
// Detect if we have more than one ReactDOM instance
178182
return (
179-
Object.keys(renderers).filter(key => isReactDOM(renderers[key])).length > 1
183+
Object.keys(renderers).filter(id => isReactDOM(renderers[id])).length > 1
180184
);
181185
}
182186
const hook = ({
@@ -186,10 +190,10 @@ function installGlobalHook(window: Object) {
186190
inject: function(renderer) {
187191
var id = Math.random().toString(16).slice(2);
188192
hook._renderers[id] = renderer;
189-
var duplicatedReact = detectDuplicatedReact(hook._renderers);
190-
// FIXME: Do we need to report buildType of smth other than ReactDOM?
193+
var isReactDuplicated = detectDuplicatedReact(hook._renderers);
194+
191195
// Currently we overwrite buildType with each injected renderer's type
192-
var reactBuildType = duplicatedReact
196+
var reactBuildType = isReactDuplicated
193197
? 'duplicated'
194198
: detectReactBuildType(renderer);
195199

0 commit comments

Comments
 (0)