Skip to content

Commit 238e7d9

Browse files
committed
Avoid crashes on environments without process.env. Fixes #39
1 parent b7ef178 commit 238e7d9

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/components/createConnect.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,6 @@ export default function createConnect(React) {
144144
this.trySubscribe();
145145
}
146146

147-
componentWillUpdate() {
148-
if (process.env.NODE_ENV !== 'production') {
149-
if (this.version === version) {
150-
return;
151-
}
152-
153-
// We are hot reloading!
154-
this.version = version;
155-
156-
// Update the state and bindings.
157-
this.trySubscribe();
158-
this.recomputeStateProps();
159-
this.recomputeDispatchProps();
160-
this.recomputeState();
161-
}
162-
}
163-
164147
componentWillReceiveProps(nextProps) {
165148
if (!shallowEqual(nextProps, this.props)) {
166149
this.recomputeState(nextProps);
@@ -189,6 +172,32 @@ export default function createConnect(React) {
189172
}
190173
}
191174

175+
if ((
176+
// Node-like CommonJS environments (Browserify, Webpack)
177+
typeof process !== 'undefined' &&
178+
typeof process.env !== 'undefined' &&
179+
process.env.NODE_ENV !== 'production'
180+
) ||
181+
// React Native
182+
typeof __DEV__ !== 'undefined' &&
183+
__DEV__ //eslint-disable-line no-undef
184+
) {
185+
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
186+
if (this.version === version) {
187+
return;
188+
}
189+
190+
// We are hot reloading!
191+
this.version = version;
192+
193+
// Update the state and bindings.
194+
this.trySubscribe();
195+
this.recomputeStateProps();
196+
this.recomputeDispatchProps();
197+
this.recomputeState();
198+
};
199+
}
200+
192201
return Connect;
193202
};
194203
};

0 commit comments

Comments
 (0)