From 5091a8ce190106cb8ebdfc88e9da7522f0092784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr?= <8machy@seznam.cz> Date: Sun, 14 Jul 2024 11:50:09 +0200 Subject: [PATCH] Trigger spa:request:end and spa:navigation:end when navigation is aborted. --- packages/signalizejs/src/modules/spa.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/signalizejs/src/modules/spa.js b/packages/signalizejs/src/modules/spa.js index 625886b..c944498 100755 --- a/packages/signalizejs/src/modules/spa.js +++ b/packages/signalizejs/src/modules/spa.js @@ -87,8 +87,17 @@ export default async ({ params, resolve, root }, config) => { error: null }; + let navigationRequestIsRunning = false; + if (abortNavigationRequestController !== undefined) { abortNavigationRequestController.abort(); + + if (navigationRequestIsRunning) { + navigationRequestIsRunning = false; + dispatch('spa:request:end', { ...dispatchEventData, navigationResponse: null }); + } + + dispatch('spa:navigation:end', dispatchEventData); } abortNavigationRequestController = new AbortController(); @@ -119,12 +128,14 @@ export default async ({ params, resolve, root }, config) => { } else { dispatch('spa:request:start', { ...dispatchEventData }); + navigationRequestIsRunning = true; navigationResponse = await ajax(urlString, { signal: abortNavigationRequestController.signal, headers: { Accept: 'text/html, application/xhtml+xml' } }); + navigationRequestIsRunning = false; abortNavigationRequestController = undefined; const requestIsWithoutErroor = navigationResponse.error === null;