Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wrangler] debounce restarts when changes are made to the assets directory #6866

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading