Skip to content

unloadApplication not updating state of SKIP_BECAUSE_BROKEN app #1301

Description

@JoaoGiesteira33

Description
I am trying to make my angular web app recover from scenarios where one single-spa app is shutdown and then turned back on again. To this end, I am using mount timeouts to detect if an app is turned off. When it is, I want to manually unload it so that, in the future, if turned back on, the user doesn't have to manually reload the entire web app.

To this end, I have the following configs in my apps, so that the app updates its state to SKIP_BECAUSE_BROKEN:
export const timeouts = { mount: { millis: 1000, dieOnTimeout: true, }, };

Then, I am catching the app-change event and unloading all SKIP_BECAUSE_BROKEN apps:

window.addEventListener('single-spa:app-change', (evt: any) => {
      const appsByNewStatus = evt.detail.appsByNewStatus;
      if (isNullishOrEmpty(appsByNewStatus[SKIP_BECAUSE_BROKEN])) return;
      // Unload broken apps.
      for (const brokenApp of appsByNewStatus[SKIP_BECAUSE_BROKEN]) {
        unloadApplication(brokenApp)
          .then(() => {
            const newAppStatus = getAppStatus(brokenApp);
          })
      }
    });

Steps

  1. Start the app.
  2. Enter web app go to a page that makes the app get mounted.
  3. Leave the page so that app gets unmounted.
  4. Turn of the app.
  5. Enter another page that will try to mount the app.
  6. Mount will time out because app is turned off and app will change state to SKIP_BECAUSE_BROKEN.
  7. unloadApplication is called in SKIP_BECAUSE_BROKEN app.
  8. App doesn't update state.

Expected behavior
Expected app to update state to NOT_LOADED.

Additional context
I am aware of handling LOAD_ERROR status to retry module loading, as described in the API:

singleSpa.addErrorHandler((err) => {
  if (singleSpa.getAppStatus(err.appOrParcelName) === singleSpa.LOAD_ERROR) {
    System.delete(System.resolve(err.appOrParcelName));
  }
});

But this only works if the app never gets mounted. If the app does get mounted, and I don't change its state to SKIP_BECAUSE_BROKEN, it will instead automatically unmount. Then, there is no way of knowing if it is unmounted because of normal behavior or because the app was turned off.

I am also aware of a pull request related to this issue. I updated the version of the framework:
"single-spa": "^7.0.0-beta.3",
Now, unlike before, my code enters in the then() branch after executing unloadApplication, but the problem remains, the state of the app doesn't update.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions