Skip to content

Commit

Permalink
[wrangler] debounce restarts when changes are made to the assets dire…
Browse files Browse the repository at this point in the history
…ctory (#6866)

* debounce restarts when changes are made to the assets directory

closes #6865

* add changeset
  • Loading branch information
zwily authored Oct 1, 2024
1 parent 6009bb4 commit c75b0d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-shirts-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: debounce restarting worker on assets dir file changes
13 changes: 11 additions & 2 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { run } from "./experimental-flags";
import isInteractive from "./is-interactive";
import { logger } from "./logger";
import * as metrics from "./metrics";
import { debounce } from "./pages/utils";
import { getLegacyAssetPaths, getSiteAssetPaths } from "./sites";
import {
getAccountFromCache,
Expand Down Expand Up @@ -858,14 +859,18 @@ export async function startDev(args: StartDevOptions) {
await assetsWatcher?.close();

if (assetsOptions) {
const debouncedRerender = debounce(async () => {
rerender(await getDevReactElement(config));
}, 100);

assetsWatcher = watch(assetsOptions.directory, {
persistent: true,
ignoreInitial: true,
}).on("all", async (eventName, changedPath) => {
const message = getAssetChangeMessage(eventName, changedPath);

logger.log(`🌀 ${message}...`);
rerender(await getDevReactElement(config));
debouncedRerender();
});
}
}
Expand Down Expand Up @@ -998,14 +1003,18 @@ export async function startDev(args: StartDevOptions) {
rerender = devReactElement.rerender;

if (assetsOptions && !args.experimentalDevEnv) {
const debouncedRerender = debounce(async () => {
rerender(await getDevReactElement(config));
}, 100);

assetsWatcher = watch(assetsOptions.directory, {
persistent: true,
ignoreInitial: true,
}).on("all", async (eventName, filePath) => {
const message = getAssetChangeMessage(eventName, filePath);

logger.log(`🌀 ${message}...`);
rerender(await getDevReactElement(config));
debouncedRerender();
});
}

Expand Down

0 comments on commit c75b0d9

Please sign in to comment.