Skip to content

Commit 2ba6c62

Browse files
committed
Fix SSR error: use onMount cleanup instead of onDestroy for window access
1 parent 9cd6b51 commit 2ba6c62

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/routes/+page.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { onMount, onDestroy } from 'svelte';
2+
import { onMount } from 'svelte';
33
import { base } from '$app/paths';
44
import { goto } from '$app/navigation';
55
import Icon from '$lib/components/common/Icon.svelte';
@@ -22,10 +22,9 @@
2222
2323
onMount(() => {
2424
window.addEventListener('keydown', handleGlobalKeydown);
25-
});
26-
27-
onDestroy(() => {
28-
window.removeEventListener('keydown', handleGlobalKeydown);
25+
return () => {
26+
window.removeEventListener('keydown', handleGlobalKeydown);
27+
};
2928
});
3029
3130
function handleSearchKeydown(event: KeyboardEvent) {

0 commit comments

Comments
 (0)