-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I think it makes sense that if registerPromise is called after unmount, that it should return something like new Promise(() => {}), ie a Promise that never will resolve.
I ran into this in this situation: I had forgotten to register one particular Promise, and so the component unmounted (because of a client-side redirect that occurred on page load) before most of my Promises even ran, and so the fact that I registered later Promises was irrelevant.
Here's how I'm using this by the way:
componentDidMount() {
this.pollInterval = setInterval(() => this.poll(), 30 * 1000);
this.poll();
}
componentWillUnmount() {
if (this.pollInterval) {
clearInterval(this.pollInterval);
this.pollInterval = null;
}
}
poll() {
this.props.registerPromise(Promise.resolve())
.then(() => this.props.registerPromise(this.checkStatus()))
.then(details => details || this.props.registerPromise(this.checkIncident()))
.then(details => details || this.props.registerPromise(this.checkMaintenance()))
.then(details => this.setState({details}));
}When I was missing the registerPromise around the initial Promise.resolve() I would trigger the issue described here every time I loaded the page that did a redirect (and thus a component unmount) on startup.
Arguably this was me mis-using the API by forgetting a registration, but it still seems like this should have been able to work.