Skip to content

Commit 542d662

Browse files
Rich-HarrisRich Harris
andauthored
add HMR to fallback error pages in dev (#9497)
* add HMR to fallback error pages in dev * Update packages/kit/src/runtime/server/utils.js --------- Co-authored-by: Rich Harris <[email protected]>
1 parent becf2b0 commit 542d662

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/great-wasps-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': minor
3+
---
4+
5+
feat: add HMR to fallback error pages during dev

packages/kit/src/runtime/server/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DEV } from 'esm-env';
12
import { json, text } from '../../exports/index.js';
23
import { coalesce_to_error } from '../../utils/error.js';
34
import { negotiate } from '../../utils/http.js';
@@ -52,7 +53,14 @@ export function allowed_methods(mod) {
5253
* @param {string} message
5354
*/
5455
export function static_error_page(options, status, message) {
55-
return text(options.templates.error({ status, message }), {
56+
let page = options.templates.error({ status, message });
57+
58+
if (DEV) {
59+
// inject Vite HMR client, for easier debugging
60+
page = page.replace('</head>', '<script type="module" src="/@vite/client"></script></head>');
61+
}
62+
63+
return text(page, {
5664
headers: { 'content-type': 'text/html; charset=utf-8' },
5765
status
5866
});

0 commit comments

Comments
 (0)