Skip to content

Commit

Permalink
fix: dev client script being loaded twice (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Oct 16, 2023
1 parent 206d500 commit bbedea5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/runtime/entrypoints/client.ts → src/runtime/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
let ws: WebSocket;

let closed = false;

let reconnectTimer: number;
const backoff = [
0,
Expand All @@ -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) {
Expand All @@ -39,7 +37,6 @@ function reconnect() {

try {
connect(true);
closed = false;
clearTimeout(reconnectTimer);
} catch (_err) {
reconnect();
Expand All @@ -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();
});

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/entrypoints/main_dev.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import "preact/debug";
import "./client.ts";
import "../client.ts";
export * from "./main.ts";

0 comments on commit bbedea5

Please sign in to comment.