Skip to content

Commit 6be8792

Browse files
authored
fix: auto-reload page when stale JS chunks cause blank screen (#63)
After a new deployment, cached HTML pages reference old hashed JS chunk filenames that no longer exist, resulting in 404s and a blank page. This adds a client error hook that detects the module import failure and automatically reloads to fetch fresh assets. Closes #62
1 parent f27eb77 commit 6be8792

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/hooks.client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { HandleClientError } from '@sveltejs/kit'
2+
3+
export const handleError: HandleClientError = ({ error }) => {
4+
// When a new deployment happens, old JS chunks are gone.
5+
// Detect this and reload the page to get fresh assets.
6+
if (error instanceof TypeError && error.message.includes('Importing a module script failed')) {
7+
window.location.reload()
8+
return
9+
}
10+
}

0 commit comments

Comments
 (0)