From 6066cc9cfa7887453f7b5473ae8f545617314dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr?= <8machy@seznam.cz> Date: Sun, 14 Jul 2024 11:02:35 +0200 Subject: [PATCH 1/3] Set abortNavigationRequestController to undefined after the request finishes. --- packages/signalizejs/src/modules/spa.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/signalizejs/src/modules/spa.js b/packages/signalizejs/src/modules/spa.js index a60f20a..625886b 100755 --- a/packages/signalizejs/src/modules/spa.js +++ b/packages/signalizejs/src/modules/spa.js @@ -21,8 +21,8 @@ export default async ({ params, resolve, root }, config) => { /** @type {import('../../types/modules/spa').HistoryState|undefined} */ let currentState; - /** @type {AbortController} */ - let abortNavigationController; + /** @type {AbortController|undefined} */ + let abortNavigationRequestController; const spaVersion = null; const host = window.location.host; /** @type {import('../../types/modules/spa').ResponseCache} */ @@ -87,11 +87,11 @@ export default async ({ params, resolve, root }, config) => { error: null }; - if (abortNavigationController !== undefined) { - abortNavigationController.abort(); + if (abortNavigationRequestController !== undefined) { + abortNavigationRequestController.abort(); } - abortNavigationController = new AbortController(); + abortNavigationRequestController = new AbortController(); const { stateAction = defaultStateAction } = data; const url = data.url instanceof URL ? data.url : createUrl(data.url); @@ -120,11 +120,12 @@ export default async ({ params, resolve, root }, config) => { dispatch('spa:request:start', { ...dispatchEventData }); navigationResponse = await ajax(urlString, { - signal: abortNavigationController.signal, + signal: abortNavigationRequestController.signal, headers: { Accept: 'text/html, application/xhtml+xml' } }); + abortNavigationRequestController = undefined; const requestIsWithoutErroor = navigationResponse.error === null; if (requestIsWithoutErroor) { From 7ab7cc0d89ee5c63f6eb6bf6a03ad86630323c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr?= <8machy@seznam.cz> Date: Sun, 14 Jul 2024 11:43:37 +0200 Subject: [PATCH 2/3] Replace only javascript script tag --- packages/signalizejs/src/modules/snippets.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/signalizejs/src/modules/snippets.js b/packages/signalizejs/src/modules/snippets.js index d882ef8..4bb2516 100755 --- a/packages/signalizejs/src/modules/snippets.js +++ b/packages/signalizejs/src/modules/snippets.js @@ -73,6 +73,12 @@ export default async ({ params, resolve, root }) => { } for (const script of existingSnippet.querySelectorAll('script')) { + const scriptTypeAttribute = script.getAttribute('type'); + + if (scriptTypeAttribute && !['module', 'text/javascript'].includes(scriptTypeAttribute)) { + continue; + } + const scriptElement = document.createElement('script'); scriptElement.innerHTML = script.innerHTML; scriptElement.async = false; 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 3/3] 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;