moved require(emptyObject) to inline calls to get around referential mismatch
Due to how Jest and other mocking libraries work in userland, modules that are required might not be referentially equal at various stages of the application lifecycle. This isnt a perfect fix, but by having the require calls inline, it has a better liklihood of ensuring emptyObject is the same reference
Dominic Gannaway committed
Feb 22, 2017 at 16:12 UTC
3a7d6f53849c932dd226417da6642a735e00e6d2
2 files changed
+6
-5
src/isomorphic/modern/class/ReactBaseClasses.js
+4
-3
@@ -14,7 +14,6 @@
14
var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue');
15
16
var canDefineProperty = require('canDefineProperty');
17
-var emptyObject = require('emptyObject');
17
var invariant = require('invariant');
18
var warning = require('warning');
19
@@ -24,7 +23,8 @@ var warning = require('warning');
23
function ReactComponent(props, context, updater) {
24
this.props = props;
25
this.context = context;
27
- this.refs = emptyObject;
26
+ // emptyObject is inlined to help avoid module mocking referential mismatches
27
+ this.refs = require('emptyObject');
28
// We initialize the default updater but the real one gets injected by the
29
// renderer.
30
this.updater = updater || ReactNoopUpdateQueue;
@@ -133,7 +133,8 @@ function ReactPureComponent(props, context, updater) {
133
// Duplicated from ReactComponent.
134
this.props = props;
135
this.context = context;
136
- this.refs = emptyObject;
136
+ // emptyObject is inlined to help avoid module mocking referential mismatches
137
+ this.refs = require('emptyObject');
138
// We initialize the default updater but the real one gets injected by the
139
// renderer.
140
this.updater = updater || ReactNoopUpdateQueue;
src/renderers/shared/fiber/ReactChildFiber.js
+2
-2
@@ -32,7 +32,6 @@ var ReactFiber = require('ReactFiber');
32
var ReactTypeOfSideEffect = require('ReactTypeOfSideEffect');
33
var ReactTypeOfWork = require('ReactTypeOfWork');
34
35
-var emptyObject = require('emptyObject');
35
var getIteratorFn = require('getIteratorFn');
36
var invariant = require('invariant');
37
var ReactFeatureFlags = require('ReactFeatureFlags');
@@ -101,7 +100,8 @@ function coerceRef(current: Fiber | null, element: ReactElement) {
100
return current.ref;
101
}
102
const ref = function(value) {
104
- const refs = inst.refs === emptyObject ? (inst.refs = {}) : inst.refs;
103
+ // emptyObject is inlined to help avoid module mocking referential mismatches
104
+ const refs = inst.refs === require('emptyObject') ? (inst.refs = {}) : inst.refs;
105
if (value === null) {
106
delete refs[stringRef];
107
} else {