Skip to content

Commit

Permalink
fix: copy server URLs to Vite dev server (#12127)
Browse files Browse the repository at this point in the history
* fix: copy server URLs to Vite dev server

* Changeset
  • Loading branch information
ascorbic authored Oct 4, 2024
1 parent abf9a89 commit 55e9cd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-moles-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevents Vite emitting an error when restarting itself
10 changes: 8 additions & 2 deletions packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) => {
Expand All @@ -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

Expand Down

0 comments on commit 55e9cd8

Please sign in to comment.