[HOS-313] state.js: when a routing error occurs, delete it (#4410)

In some cases, a routing failure can cause the failure to be cached. When the
router has a cached failure, pushing such a route will never call
routeChangeComplete, and thus on_load event will never be fired for that route.

Purposely clearing the error from the router allows the page to properly load
on subsequent attempts without refreshing the app.
This commit is contained in:
Masen Furer 2024-11-21 10:27:44 -08:00 committed by GitHub
parent 4571524e1c
commit 81583d45ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -762,7 +762,7 @@ export const useEventLoop = (
window.onunhandledrejection = function (event) {
addEvents([
Event(`${exception_state_name}.handle_frontend_exception`, {
stack: event.reason.stack,
stack: event.reason?.stack,
component_stack: "",
}),
]);
@ -837,11 +837,20 @@ export const useEventLoop = (
}
};
const change_complete = () => addEvents(onLoadInternalEvent());
const change_error = () => {
// Remove cached error state from router for this page, otherwise the
// page will never send on_load events again.
if (router.components[router.pathname].error) {
delete router.components[router.pathname].error;
}
}
router.events.on("routeChangeStart", change_start);
router.events.on("routeChangeComplete", change_complete);
router.events.on("routeChangeError", change_error);
return () => {
router.events.off("routeChangeStart", change_start);
router.events.off("routeChangeComplete", change_complete);
router.events.off("routeChangeError", change_error);
};
}, [router]);