Skip to content
Open
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
27 changes: 19 additions & 8 deletions packages/signalizejs/src/modules/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const spaCacheHeader = config?.cacheHeader ?? `${spaHeaderPrefix}Cache-Control`;
const spaAppVersionHeader = config?.appVersionHeader ?? `${spaHeaderPrefix}App-Version`;
const spaTransitionsHeader = config?.appVersionHeader ?? `${spaHeaderPrefix}Transitions`;
const spaReloadHeader = config?.reloadHeader ?? `${spaHeaderPrefix}Reload`;
const defaultStateAction = 'push';

/** @type {import('../../types/modules/spa').HistoryState|undefined} */
Expand Down Expand Up @@ -146,15 +147,26 @@

navigationRequestIsRunning = false;
abortNavigationRequestController = undefined;
const requestIsWithoutErroor = navigationResponse.error === null;

if (requestIsWithoutErroor) {
if (navigationResponse.response.redirected) {
urlString = navigationResponse.response.url;
}
const requestIsWithoutError = navigationResponse.error === null;

if (requestIsWithoutError) {
try {
responseData = navigationResponse.response === null ? '' : await navigationResponse.response.text();
const { response } = navigationResponse;
const responseIsNull = response === null;
responseData = responseIsNull ? '' : await response.text();

if (!responseIsNull && response.redirected) {
const responseUrl = new URL(response.url);
if (window.location.protocol !== responseUrl.protocol
|| window.location.hostname !== responseUrl.hostname
|| spaReloadHeader in response.headers
) {
window.location = response.url;
} else {
urlString = responseUrl.toString();
}
}

} catch (error) {
dispatchEventData.error = error;
console.error(error);
Expand Down Expand Up @@ -241,7 +253,7 @@

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

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

Check failure on line 256 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 256 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 All @@ -251,7 +263,6 @@

if (!navigationScrollStopped) {
if (urlHash !== null && urlHash.trim().length > 2) {
console.log()
scrollElementIntoView(url.hash);
} else {
queueMicrotask(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/signalizejs/types/modules/spa.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface SpaConfig {
cacheHeader?: string;
/** The app version header name. Used to dispatch event, that SPA version has changed. */
appVersionHeader?: string;
/** The reload header name. Used to trigger full page reload. */
reloadHeader?: string;
}

export interface HistoryState {
Expand Down
Loading