From 35795a1a54b2bfaf331c58ca91b47e5672e08c4e Mon Sep 17 00:00:00 2001 From: Hippo <6137925+hippotastic@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:19:54 +0100 Subject: [PATCH] Fix watchfile multiple dev server restart (#12353) --- .changeset/famous-timers-move.md | 5 +++++ packages/astro/src/core/dev/restart.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/famous-timers-move.md diff --git a/.changeset/famous-timers-move.md b/.changeset/famous-timers-move.md new file mode 100644 index 000000000000..ca9f914c0885 --- /dev/null +++ b/.changeset/famous-timers-move.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue in dev server watch file handling that could cause multiple restarts for a single file change. diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index b7eab38af66b..9c3dc074296b 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -169,7 +169,9 @@ export async function createContainerWithAutomaticRestart({ // Restart the Astro dev server instead of Vite's when the API is called by plugins. // Ignore the `forceOptimize` parameter for now. - restart.container.viteServer.restart = () => handleServerRestart(); + restart.container.viteServer.restart = async () => { + if (!restart.container.restartInFlight) await handleServerRestart(); + }; // Set up shortcuts