diff --git a/src/runtime/entrypoints/client.ts b/src/runtime/client.ts similarity index 85% rename from src/runtime/entrypoints/client.ts rename to src/runtime/client.ts index 34b7fd3112e..21d1a656143 100644 --- a/src/runtime/entrypoints/client.ts +++ b/src/runtime/client.ts @@ -1,7 +1,5 @@ let ws: WebSocket; -let closed = false; - let reconnectTimer: number; const backoff = [ 0, @@ -25,7 +23,7 @@ const backoff = [ ]; let backoffIdx = 0; function reconnect() { - if (!closed) return; + if (ws.readyState !== ws.CLOSED) return; reconnectTimer = setTimeout(() => { if (backoffIdx === 0) { @@ -39,7 +37,6 @@ function reconnect() { try { connect(true); - closed = false; clearTimeout(reconnectTimer); } catch (_err) { reconnect(); @@ -54,18 +51,19 @@ function connect(forceReload?: boolean) { ); ws.addEventListener("open", () => { - console.log( - `%c Fresh %c Connected to development server.`, - "background-color: #86efac; color: black", - "color: inherit", - ); if (forceReload) { location.reload(); + } else { + backoffIdx = 0; + console.log( + `%c Fresh %c Connected to development server.`, + "background-color: #86efac; color: black", + "color: inherit", + ); } }); ws.addEventListener("close", () => { - closed = true; reconnect(); }); diff --git a/src/runtime/entrypoints/main_dev.ts b/src/runtime/entrypoints/main_dev.ts index 021884116c0..4fe0bdb9424 100644 --- a/src/runtime/entrypoints/main_dev.ts +++ b/src/runtime/entrypoints/main_dev.ts @@ -1,3 +1,3 @@ import "preact/debug"; -import "./client.ts"; +import "../client.ts"; export * from "./main.ts";