Fix page reloading on initial update (#21410)

Remove the hash event listener before reloading the page, as the reload was being swallowed by our router.

Along the way, refactor out routing logic form app.tsx to avoid causing a circular import.
This commit is contained in:
James Salter 2022-03-16 12:20:06 +00:00 committed by GitHub
parent 1f97bc2325
commit adad5e16c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 58 deletions

View file

@ -28,6 +28,7 @@ import { logger } from "matrix-js-sdk/src/logger";
import VectorBasePlatform from './VectorBasePlatform';
import { parseQs } from "../url_utils";
import { reloadPage } from "../routing";
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
@ -128,9 +129,11 @@ export default class WebPlatform extends VectorBasePlatform {
//
// Ideally, loading an old copy would be impossible with the
// cache-control: nocache HTTP header set, but Firefox doesn't always obey it :/
console.log("startUpdater, current version is " + this.getNormalizedAppVersion(process.env.VERSION));
this.pollForUpdate((version: string, newVersion: string) => {
const query = parseQs(location);
if (query.updated === "1") {
console.log("Update reloaded but still on an old version, stopping");
// We just reloaded already and are still on the old version!
// Show the toast rather than reload in a loop.
showUpdateToast(version, newVersion);
@ -146,8 +149,7 @@ export default class WebPlatform extends VectorBasePlatform {
suffix = "&" + suffix;
}
// This line has the effect of loading the page at the new location
window.location.href = window.location.href + suffix;
reloadPage(window.location.href + suffix);
});
setInterval(() => this.pollForUpdate(showUpdateToast, hideUpdateToast), POKE_RATE_MS);
}
@ -165,10 +167,14 @@ export default class WebPlatform extends VectorBasePlatform {
if (currentVersion !== mostRecentVersion) {
if (this.shouldShowUpdate(mostRecentVersion)) {
console.log("Update available to " + mostRecentVersion + ", will notify user");
showUpdate(currentVersion, mostRecentVersion);
} else {
console.log("Update available to " + mostRecentVersion + " but won't be shown");
}
return { status: UpdateCheckStatus.Ready };
} else {
console.log("No update available, already on " + mostRecentVersion);
showNoUpdate?.();
}