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

fix: copy server URLs to Vite dev server #12127

Merged
merged 2 commits into from
Oct 4, 2024
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/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
Loading