fix: move scroll lock to afterUpdate to avoid SSR document access
The $: reactive block runs during SSR component init. Use afterUpdate with a mounted guard instead so document is only accessed client-side. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { onMount, onDestroy, afterUpdate } from 'svelte';
|
||||
|
||||
/** @type {boolean} */
|
||||
export let open = false;
|
||||
@@ -11,6 +10,7 @@
|
||||
let dragOffset = 0;
|
||||
let dragging = false;
|
||||
let locked = false;
|
||||
let mounted = false;
|
||||
|
||||
/** @type {number|null} */
|
||||
let startY = null;
|
||||
@@ -29,8 +29,9 @@
|
||||
/** @type {HTMLDivElement|null} */
|
||||
let sheetEl = null;
|
||||
|
||||
// Body scroll lock
|
||||
$: if (browser) {
|
||||
// Body scroll lock — managed in afterUpdate to avoid SSR document access
|
||||
afterUpdate(() => {
|
||||
if (!mounted) return;
|
||||
if (open) {
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
} else {
|
||||
@@ -39,7 +40,7 @@
|
||||
dragging = false;
|
||||
locked = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} e
|
||||
@@ -69,6 +70,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
mounted = true;
|
||||
document.addEventListener('keydown', handleKeydown);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user