Skip to content

Commit

Permalink
Trigger spa:request:end and spa:navigation:end when navigation is abo…
Browse files Browse the repository at this point in the history
…rted.
  • Loading branch information
Machy8 committed Jul 14, 2024
1 parent 7ab7cc0 commit 5091a8c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/signalizejs/src/modules/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 5091a8c

Please sign in to comment.