Skip to content

Commit

Permalink
Merge pull request #45 from signalizejs/fixes2
Browse files Browse the repository at this point in the history
Fixes2
  • Loading branch information
Machy8 authored Jul 14, 2024
2 parents efac627 + 5091a8c commit 0e6c9a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/signalizejs/src/modules/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 18 additions & 6 deletions packages/signalizejs/src/modules/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down Expand Up @@ -87,11 +87,20 @@ export default async ({ params, resolve, root }, config) => {
error: null
};

if (abortNavigationController !== undefined) {
abortNavigationController.abort();
let navigationRequestIsRunning = false;

if (abortNavigationRequestController !== undefined) {
abortNavigationRequestController.abort();

if (navigationRequestIsRunning) {
navigationRequestIsRunning = false;
dispatch('spa:request:end', { ...dispatchEventData, navigationResponse: null });
}

dispatch('spa:navigation:end', dispatchEventData);
}

abortNavigationController = new AbortController();
abortNavigationRequestController = new AbortController();
const { stateAction = defaultStateAction } = data;
const url = data.url instanceof URL ? data.url : createUrl(data.url);

Expand Down Expand Up @@ -119,12 +128,15 @@ export default async ({ params, resolve, root }, config) => {
} else {
dispatch('spa:request:start', { ...dispatchEventData });

navigationRequestIsRunning = true;
navigationResponse = await ajax(urlString, {
signal: abortNavigationController.signal,
signal: abortNavigationRequestController.signal,
headers: {
Accept: 'text/html, application/xhtml+xml'
}
});
navigationRequestIsRunning = false;
abortNavigationRequestController = undefined;
const requestIsWithoutErroor = navigationResponse.error === null;

if (requestIsWithoutErroor) {
Expand Down

0 comments on commit 0e6c9a0

Please sign in to comment.