Skip to content

Maybe should pre-trash Promises if registerPromise called after unmount? #3

@glasser

Description

@glasser

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions