Skip to content

Commit 6c8206a

Browse files
authored
fix: convert compile error on hmr (#592)
* fix: patch compiler error so that vite shows nice error overlay * chore: remove useless try/catch
1 parent 055dcf2 commit 6c8206a

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

.changeset/small-oranges-give.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
show correct error overlay for compiler errors during hot update

packages/vite-plugin-svelte/src/handle-hot-update.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { log, logCompilerWarnings } from './utils/log';
44
import { SvelteRequest } from './utils/id';
55
import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache';
66
import { ResolvedOptions } from './utils/options';
7+
import { toRollupError } from './utils/error';
78

89
/**
910
* Vite-specific HMR handling
@@ -32,7 +33,7 @@ export async function handleHotUpdate(
3233
cache.update(compileData);
3334
} catch (e) {
3435
cache.setError(svelteRequest, e);
35-
throw e;
36+
throw toRollupError(e, options);
3637
}
3738

3839
const affectedModules = [...modules];

packages/vite-plugin-svelte/src/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,7 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
219219
}
220220
const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
221221
if (svelteRequest) {
222-
try {
223-
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options);
224-
} catch (e) {
225-
throw toRollupError(e, options);
226-
}
222+
return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options);
227223
}
228224
},
229225
async buildEnd() {

0 commit comments

Comments
 (0)