mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix: error overlay message escape (#12305)
Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
parent
e10b03e88c
commit
f5f71094ec
3 changed files with 28 additions and 0 deletions
5
.changeset/breezy-plums-clap.md
Normal file
5
.changeset/breezy-plums-clap.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a case where the error overlay would not escape the message
|
|
@ -105,6 +105,7 @@ export function enhanceViteSSRError({
|
|||
}
|
||||
|
||||
export interface AstroErrorPayload {
|
||||
__isEnhancedAstroErrorPayload: true;
|
||||
type: ErrorPayload['type'];
|
||||
err: Omit<ErrorPayload['err'], 'loc'> & {
|
||||
name?: string;
|
||||
|
@ -164,6 +165,7 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): Promise<Astro
|
|||
: undefined;
|
||||
|
||||
return {
|
||||
__isEnhancedAstroErrorPayload: true,
|
||||
type: 'error',
|
||||
err: {
|
||||
...err,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { EventEmitter } from 'node:events';
|
||||
import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import type * as vite from 'vite';
|
||||
import { collectErrorMetadata } from '../errors/dev/utils.js';
|
||||
import { getViteErrorPayload } from '../errors/dev/vite.js';
|
||||
import type { ModuleLoader, ModuleLoaderEventEmitter } from './loader.js';
|
||||
|
||||
export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader {
|
||||
|
@ -43,6 +46,24 @@ export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader {
|
|||
}
|
||||
const msg = args[0] as vite.HMRPayload;
|
||||
if (msg?.type === 'error') {
|
||||
// If we have an error, but it didn't go through our error enhancement program, it means that it's a HMR error from
|
||||
// vite itself, which goes through a different path. We need to enhance it here.
|
||||
if (!(msg as any)['__isEnhancedAstroErrorPayload']) {
|
||||
const err = collectErrorMetadata(msg.err, pathToFileURL(viteServer.config.root));
|
||||
getViteErrorPayload(err).then((payload) => {
|
||||
events.emit('hmr-error', {
|
||||
type: 'error',
|
||||
err: {
|
||||
message: payload.err.message,
|
||||
stack: payload.err.stack,
|
||||
},
|
||||
});
|
||||
|
||||
args[0] = payload;
|
||||
_wsSend.apply(this, args);
|
||||
});
|
||||
return;
|
||||
}
|
||||
events.emit('hmr-error', msg);
|
||||
}
|
||||
_wsSend.apply(this, args);
|
||||
|
|
Loading…
Reference in a new issue