mirror of
https://github.com/withastro/astro.git
synced 2025-01-13 22:11:20 -05:00
fix: copy server URLs to Vite dev server (#12127)
* fix: copy server URLs to Vite dev server * Changeset
This commit is contained in:
parent
abf9a89ac1
commit
55e9cd8855
2 changed files with 13 additions and 2 deletions
5
.changeset/dull-moles-talk.md
Normal file
5
.changeset/dull-moles-talk.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Prevents Vite emitting an error when restarting itself
|
|
@ -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());
|
logger.info(null, (logMsg + ' Restarting...').trim());
|
||||||
const container = restart.container;
|
const container = restart.container;
|
||||||
const result = await restartContainer(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 success. Add new watches because this is a new container with a new Vite server
|
||||||
restart.container = result;
|
restart.container = result;
|
||||||
setupContainer();
|
setupContainer();
|
||||||
|
if (server) {
|
||||||
|
// Vite expects the resolved URLs to be available
|
||||||
|
server.resolvedUrls = result.viteServer.resolvedUrls;
|
||||||
|
}
|
||||||
|
|
||||||
resolveRestart(null);
|
resolveRestart(null);
|
||||||
}
|
}
|
||||||
restartComplete = new Promise<Error | null>((resolve) => {
|
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.
|
// Restart the Astro dev server instead of Vite's when the API is called by plugins.
|
||||||
// Ignore the `forceOptimize` parameter for now.
|
// Ignore the `forceOptimize` parameter for now.
|
||||||
restart.container.viteServer.restart = () => handleServerRestart();
|
restart.container.viteServer.restart = () =>
|
||||||
|
handleServerRestart('', restart.container.viteServer);
|
||||||
|
|
||||||
// Set up shortcuts
|
// Set up shortcuts
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue