diff options
author | 2024-10-04 19:33:42 +0100 | |
---|---|---|
committer | 2024-10-04 19:33:42 +0100 | |
commit | 55e9cd88551ac56ec4cab9a9f3fd9ba49b8934b9 (patch) | |
tree | a4665cc38093fbb378c6cb7b3edff324d554e7e5 | |
parent | abf9a89ac1eaec9a8934a68aeebe3c502a3b47eb (diff) | |
download | astro-55e9cd88551ac56ec4cab9a9f3fd9ba49b8934b9.tar.gz astro-55e9cd88551ac56ec4cab9a9f3fd9ba49b8934b9.tar.zst astro-55e9cd88551ac56ec4cab9a9f3fd9ba49b8934b9.zip |
fix: copy server URLs to Vite dev server (#12127)
* fix: copy server URLs to Vite dev server
* Changeset
-rw-r--r-- | .changeset/dull-moles-talk.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/dev/restart.ts | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/.changeset/dull-moles-talk.md b/.changeset/dull-moles-talk.md new file mode 100644 index 000000000..97d3d0eb2 --- /dev/null +++ b/.changeset/dull-moles-talk.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Prevents Vite emitting an error when restarting itself diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index 532863dfa..9d68f4365 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -136,7 +136,7 @@ export async function createContainerWithAutomaticRestart({ }, }; - async function handleServerRestart(logMsg = '') { + async function handleServerRestart(logMsg = '', server?: vite.ViteDevServer) { logger.info(null, (logMsg + ' Restarting...').trim()); const container = restart.container; const result = await restartContainer(container); @@ -147,6 +147,11 @@ export async function createContainerWithAutomaticRestart({ // Restart success. Add new watches because this is a new container with a new Vite server restart.container = result; setupContainer(); + if (server) { + // Vite expects the resolved URLs to be available + server.resolvedUrls = result.viteServer.resolvedUrls; + } + resolveRestart(null); } restartComplete = new Promise<Error | null>((resolve) => { @@ -171,7 +176,8 @@ 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 = () => + handleServerRestart('', restart.container.viteServer); // Set up shortcuts |