Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes2 #45

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

/** @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 @@
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 @@
} 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 Expand Up @@ -216,7 +228,7 @@

dispatch('spa:redraw:end', dispatchEventData);

let urlHash = window.location.hash ?? null;

Check failure on line 231 in packages/signalizejs/src/modules/spa.js

View workflow job for this annotation

GitHub Actions / Tests

'urlHash' is never reassigned. Use 'const' instead

Check failure on line 231 in packages/signalizejs/src/modules/spa.js

View workflow job for this annotation

GitHub Actions / Tests

'urlHash' is never reassigned. Use 'const' instead

const navigationScrollStopped = dispatch(
'spa:navigation:beforeScroll',
Expand Down
Loading