Skip to content

Commit 4e7bc95

Browse files
committed
Updates umd and commonjs builds.
1 parent a196a52 commit 4e7bc95

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

commonjs/asyncComponent.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function asyncComponent(config) {
9090
// so the mount call will not happen (but the ctor does).
9191
var _this = _possibleConstructorReturn(this, (AsyncComponent.__proto__ || Object.getPrototypeOf(AsyncComponent)).call(this, props, context));
9292

93-
if (_this.context.asyncComponents && !sharedState.id) {
93+
if (_this.context.asyncComponents != null && !sharedState.id) {
9494
sharedState.id = _this.context.asyncComponents.getNextId();
9595
}
9696
return _this;
@@ -121,14 +121,16 @@ function asyncComponent(config) {
121121
}
122122

123123
// node
124-
var isChildOfBoundary = asyncComponentsAncestor && asyncComponentsAncestor.isBoundary;
124+
var isChildOfBoundary = asyncComponentsAncestor != null && asyncComponentsAncestor.isBoundary;
125125
return serverMode === 'defer' || isChildOfBoundary ? false : doResolve();
126126
}
127127
}, {
128128
key: 'getChildContext',
129129
value: function getChildContext() {
130-
if (!this.context.asyncComponents) {
131-
return undefined;
130+
if (this.context.asyncComponents == null) {
131+
return {
132+
asyncComponentsAncestor: null
133+
};
132134
}
133135

134136
return {
@@ -150,10 +152,15 @@ function asyncComponent(config) {
150152
}, {
151153
key: 'componentDidMount',
152154
value: function componentDidMount() {
153-
if (!this.state.module) {
155+
if (this.shouldResolve()) {
154156
this.resolveModule();
155157
}
156158
}
159+
}, {
160+
key: 'shouldResolve',
161+
value: function shouldResolve() {
162+
return sharedState.module == null && sharedState.error == null && !this.resolving && typeof window !== 'undefined';
163+
}
157164
}, {
158165
key: 'resolveModule',
159166
value: function resolveModule() {
@@ -165,7 +172,7 @@ function asyncComponent(config) {
165172
if (_this3.unmounted) {
166173
return undefined;
167174
}
168-
if (_this3.context.asyncComponents) {
175+
if (_this3.context.asyncComponents != null) {
169176
_this3.context.asyncComponents.resolved(sharedState.id);
170177
}
171178
sharedState.module = module;
@@ -221,7 +228,6 @@ function asyncComponent(config) {
221228
module = _state.module,
222229
error = _state.error;
223230

224-
225231
if (error) {
226232
return ErrorComponent ? _react2.default.createElement(ErrorComponent, _extends({}, this.props, { error: error })) : null;
227233
}
@@ -230,7 +236,7 @@ function asyncComponent(config) {
230236
// RHL the local component reference will be killed by any change
231237
// to the component, this will be our signal to know that we need to
232238
// re-resolve it.
233-
if (sharedState.module == null && !this.resolving && typeof window !== 'undefined') {
239+
if (this.shouldResolve()) {
234240
this.resolveModule();
235241
}
236242

umd/react-async-component.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function asyncComponent(config) {
351351
// so the mount call will not happen (but the ctor does).
352352
var _this = _possibleConstructorReturn(this, (AsyncComponent.__proto__ || Object.getPrototypeOf(AsyncComponent)).call(this, props, context));
353353

354-
if (_this.context.asyncComponents && !sharedState.id) {
354+
if (_this.context.asyncComponents != null && !sharedState.id) {
355355
sharedState.id = _this.context.asyncComponents.getNextId();
356356
}
357357
return _this;
@@ -382,14 +382,16 @@ function asyncComponent(config) {
382382
}
383383

384384
// node
385-
var isChildOfBoundary = asyncComponentsAncestor && asyncComponentsAncestor.isBoundary;
385+
var isChildOfBoundary = asyncComponentsAncestor != null && asyncComponentsAncestor.isBoundary;
386386
return serverMode === 'defer' || isChildOfBoundary ? false : doResolve();
387387
}
388388
}, {
389389
key: 'getChildContext',
390390
value: function getChildContext() {
391-
if (!this.context.asyncComponents) {
392-
return undefined;
391+
if (this.context.asyncComponents == null) {
392+
return {
393+
asyncComponentsAncestor: null
394+
};
393395
}
394396

395397
return {
@@ -411,10 +413,15 @@ function asyncComponent(config) {
411413
}, {
412414
key: 'componentDidMount',
413415
value: function componentDidMount() {
414-
if (!this.state.module) {
416+
if (this.shouldResolve()) {
415417
this.resolveModule();
416418
}
417419
}
420+
}, {
421+
key: 'shouldResolve',
422+
value: function shouldResolve() {
423+
return sharedState.module == null && sharedState.error == null && !this.resolving && typeof window !== 'undefined';
424+
}
418425
}, {
419426
key: 'resolveModule',
420427
value: function resolveModule() {
@@ -426,7 +433,7 @@ function asyncComponent(config) {
426433
if (_this3.unmounted) {
427434
return undefined;
428435
}
429-
if (_this3.context.asyncComponents) {
436+
if (_this3.context.asyncComponents != null) {
430437
_this3.context.asyncComponents.resolved(sharedState.id);
431438
}
432439
sharedState.module = module;
@@ -482,7 +489,6 @@ function asyncComponent(config) {
482489
module = _state.module,
483490
error = _state.error;
484491

485-
486492
if (error) {
487493
return ErrorComponent ? _react2.default.createElement(ErrorComponent, _extends({}, this.props, { error: error })) : null;
488494
}
@@ -491,7 +497,7 @@ function asyncComponent(config) {
491497
// RHL the local component reference will be killed by any change
492498
// to the component, this will be our signal to know that we need to
493499
// re-resolve it.
494-
if (sharedState.module == null && !this.resolving && typeof window !== 'undefined') {
500+
if (this.shouldResolve()) {
495501
this.resolveModule();
496502
}
497503

0 commit comments

Comments
 (0)