diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index f8c3b56325..a84e83fa9c 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -172,7 +172,7 @@ export async function createContentTypesGenerator({ } const collectionInfo = collectionEntryMap[collectionKey]; if (collectionInfo.type === 'content') { - viteServer.ws.send({ + viteServer.hot.send({ type: 'error', err: new AstroError({ ...AstroErrorData.MixedContentDataCollectionError, @@ -212,7 +212,7 @@ export async function createContentTypesGenerator({ } const collectionInfo = collectionEntryMap[collectionKey]; if (collectionInfo.type === 'data') { - viteServer.ws.send({ + viteServer.hot.send({ type: 'error', err: new AstroError({ ...AstroErrorData.MixedContentDataCollectionError, @@ -359,7 +359,7 @@ async function writeContentFiles({ typeTemplateContent: string; contentEntryTypes: Pick[]; contentConfig?: ContentConfig; - viteServer: Pick; + viteServer: Pick; }) { let contentTypesStr = ''; let dataTypesStr = ''; @@ -374,7 +374,7 @@ async function writeContentFiles({ collection.type !== 'unknown' && collection.type !== collectionConfig.type ) { - viteServer.ws.send({ + viteServer.hot.send({ type: 'error', err: new AstroError({ ...AstroErrorData.ContentCollectionTypeMismatchError, @@ -387,7 +387,7 @@ async function writeContentFiles({ collection.type === 'data' ? "Try adding `type: 'data'` to your collection config." : undefined, - location: { file: '' /** required for error overlay `ws` messages */ }, + location: { file: '' /** required for error overlay `hot` messages */ }, }) as any, }); return; diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index 7a1b15ed05..fe543f558d 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -80,7 +80,7 @@ export async function restartContainer(container: Container): Promise { + // Patch `hot.send` to bubble up error events + // `hot.on('error')` does not fire for some reason + const hotSend = tempViteServer.hot.send; + tempViteServer.hot.send = (payload: HMRPayload) => { if (payload.type === 'error') { throw payload.err; } - return wsSend(payload); + return hotSend(payload); }; try { diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 28527f90e4..2fca4aff54 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -54,7 +54,7 @@ export async function handleHotUpdate( ctx.server.moduleGraph.invalidateModule(mod); } } - ctx.server.ws.send({ type: 'full-reload', path: '*' }); + ctx.server.hot.send({ type: 'full-reload', path: '*' }); } } } diff --git a/packages/astro/src/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.ts b/packages/astro/src/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.ts index b4b0c3d0c6..b94a967d61 100644 --- a/packages/astro/src/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.ts +++ b/packages/astro/src/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.ts @@ -25,21 +25,21 @@ export default function astroDevToolbar({ settings, logger }: AstroPluginOptions } }, configureServer(server) { - server.ws.on('astro:devtoolbar:error:load', (args) => { + server.hot.on('astro:devtoolbar:error:load', (args) => { logger.error( 'toolbar', `Failed to load dev toolbar app from ${args.entrypoint}: ${args.error}` ); }); - server.ws.on('astro:devtoolbar:error:init', (args) => { + server.hot.on('astro:devtoolbar:error:init', (args) => { logger.error( 'toolbar', `Failed to initialize dev toolbar app ${args.app.name} (${args.app.id}):\n${args.error}` ); }); - server.ws.on('astro:devtoolbar:app:toggled', (args) => { + server.hot.on('astro:devtoolbar:app:toggled', (args) => { // Debounce telemetry to avoid recording events when the user is rapidly toggling apps for debugging clearTimeout(telemetryTimeout); telemetryTimeout = setTimeout(() => {