Skip to content

Commit

Permalink
(feature): disable autoreload
Browse files Browse the repository at this point in the history
  • Loading branch information
aabccd021 committed Dec 25, 2024
1 parent 78b2390 commit 980292d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# https://github.com/nix-community/nix-direnv
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi
use flake
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:

- uses: HatsuneMiku3939/direnv-action@v1

- run: nix flake check

- run: bun install

- run: tsc
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:

- uses: HatsuneMiku3939/direnv-action@v1

- run: nix flake check

- run: bun install

- run: tsc
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
pkgs.bun
pkgs.biome
pkgs.typescript
pkgs.typescript-language-server
];
};

Expand Down
12 changes: 10 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
declare global {
var clients: Set<ReadableStreamDefaultController> | undefined;
var autoReload: boolean | undefined;
}

globalThis.clients ??= new Set<ReadableStreamDefaultController>();
globalThis.autoReload = globalThis.autoReload ?? true;

export function reloadClients(): void {
if (globalThis.clients !== undefined) {
Expand All @@ -12,7 +14,9 @@ export function reloadClients(): void {
}
}

reloadClients();
if (globalThis.autoReload) {
reloadClients();
}

export type LiveReloadOptions = {
/**
Expand Down Expand Up @@ -43,9 +47,13 @@ export function withHtmlLiveReload(
options?: {
eventPath?: string;
scriptPath?: string;
autoReload?: false;
},
): Fetch {
return async (req): Promise<Response> => {
if (options?.autoReload === false) {
globalThis.autoReload = false;
}
return async (req): Promise<Response> => {
if (req.method !== "GET") {
return handler(req);
}
Expand Down

0 comments on commit 980292d

Please sign in to comment.