Client: Don't run popstate handler on programmatic hash change

This commit is contained in:
Andrio Celos
2022-10-14 14:57:14 +11:00
parent 2c2deb5691
commit 260845bc6d

View File

@@ -49,15 +49,20 @@ maxPlayersBox.addEventListener('change', () => {
});
function setUrl(path: string) {
if (canPushState) {
try {
history.pushState(null, '', path);
} catch {
canPushState = false;
settingUrl = true;
try {
if (canPushState) {
try {
history.pushState(null, '', path);
} catch {
canPushState = false;
location.hash = `#${path}`;
}
} else
location.hash = `#${path}`;
}
} else
location.hash = `#${path}`;
} finally {
settingUrl = false;
}
}
function setGameUrl(gameID: string) { setUrl(`game/${gameID}`); }
@@ -177,8 +182,10 @@ function processUrl() {
}
}
let settingUrl = false;
window.addEventListener('popstate', () => {
processUrl();
if (!settingUrl)
processUrl();
});
processUrl();