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
- Start the app.
- Enter web app go to a page that makes the app get mounted.
- Leave the page so that app gets unmounted.
- Turn of the app.
- Enter another page that will try to mount the app.
- Mount will time out because app is turned off and app will change state to SKIP_BECAUSE_BROKEN.
- unloadApplication is called in SKIP_BECAUSE_BROKEN app.
- 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.
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:
Steps
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:
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.