fix live reload not letting you navigate away from the page sometimes

This commit is contained in:
りき萌 2025-09-10 18:43:37 +02:00
parent 67836213f4
commit 56be35e063

View file

@ -1,8 +1,13 @@
let shouldReload = true;
addEventListener("beforeunload", () => {
shouldReload = false;
});
// NOTE: The server never fulfills this request, it stalls forever. // NOTE: The server never fulfills this request, it stalls forever.
// Once the connection is closed, we try to connect with the server until we establish a successful // Once the connection is closed, we try to connect with the server until we establish a successful
// connection. Then we reload the page. // connection. Then we reload the page.
await fetch("/auto-reload/stall").catch(async () => { await fetch("/auto-reload/stall").catch(async () => {
while (true) { while (shouldReload) {
try { try {
let response = await fetch("/auto-reload/back-up"); let response = await fetch("/auto-reload/back-up");
if (response.status == 200) { if (response.status == 200) {