From 9249a9b1a4517f135311b10eab7012efdb5543ce Mon Sep 17 00:00:00 2001 From: Johannes Fleck Date: Thu, 26 Nov 2026 09:43:37 +0100 Subject: [PATCH 1/2] fix: Keep the app working when the browser blocks site data Reading localStorage throws a SecurityError when site data is blocked. ThemeToggle and the app layout did so during hydration, which took down the whole app. - Access storage only through $lib/client/local-storage, whose helpers fail silently; enforced by an ESLint rule. - Read stored JSON only through a zod schema, so data from older releases falls back to defaults instead of breaking at runtime. - Guard the inline theme script in app.html. - Say that tabs can't be saved instead of blaming the content size. - Document how to handle stored data and shape changes in AGENTS.md. --- AGENTS.md | 10 ++ CHANGELOG.md | 4 + e2e/blocked-storage.spec.ts | 64 ++++++++++++ eslint.config.js | 23 +++++ messages/de.json | 2 +- messages/en.json | 2 +- src/app.html | 11 ++- src/lib/client/local-storage.spec.ts | 99 +++++++++++++++++++ src/lib/client/local-storage.ts | 77 +++++++++++---- src/lib/components/Pagination.svelte | 4 +- .../layout/header/ThemeToggle.svelte | 5 +- .../components/layout/sidebar/Sidebar.svelte | 20 +--- .../storage/sidebar/resizable-panel.svelte.ts | 23 +---- .../components/trino/StatementResult.svelte | 8 +- .../editor/completion/completion-history.ts | 39 +++----- src/lib/storage/operations.svelte.spec.ts | 30 ++++++ src/lib/storage/operations.svelte.ts | 34 +++---- src/lib/storage/persistence.ts | 37 ++++++- src/lib/storage/tabs.svelte.spec.ts | 3 +- src/lib/storage/tabs.svelte.ts | 41 ++------ src/lib/stores/tab-store.svelte.ts | 51 +++------- src/lib/types/pagination.ts | 5 +- src/routes/(app)/+layout.svelte | 16 +-- src/routes/(app)/storage/+page.svelte | 32 +++--- src/routes/(app)/trino/+page.svelte | 31 +++--- 25 files changed, 428 insertions(+), 243 deletions(-) create mode 100644 e2e/blocked-storage.spec.ts create mode 100644 src/lib/client/local-storage.spec.ts diff --git a/AGENTS.md b/AGENTS.md index d5533ff6..2a2ef822 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -131,6 +131,16 @@ PostgreSQL via Drizzle ORM; schema in `src/lib/server/schema.ts` (better-auth ta For **new features**, do not add data migrations or legacy-data compatibility paths unless persisted data or an external consumer already exists and requires it. Ask if unclear. +### Browser Storage + +`localStorage` holds per-browser UI state and is treated as a disposable cache. Data that must survive a device switch or cleared site data belongs in PostgreSQL. + +- Access it only through `$lib/client/local-storage` (enforced by ESLint). Browsers that block site data throw on any access, and a throw during hydration takes down the whole app; the helpers fail silently instead. +- Read JSON only through a zod schema (`readStorageJson`, `loadFromStorage`), never with `as`. Data that doesn't match is dropped and the caller falls back to its defaults. +- Types that exist only for storage are derived from their schema (`z.infer`). Domain types that are also stored (e.g. `StorageOperation`) get a round-trip test with a `Required` fixture, so a field the schema would strip fails the test. +- Changing a stored shape: adding optional fields or removing fields needs nothing. For a new required field use `.default()`. Otherwise losing old entries is fine for UI state. Only data users would miss gets a lazy conversion: write to a new key with a version suffix (`…_v2`), read the old key if the new one is missing, convert, write the new one and remove the old one. Test it against an old-format fixture and remove it after two releases. +- No global storage version and no migration step at startup. + ### Feature Flags and Configuration Environment variables are parsed with zod at startup using the helpers in `src/lib/env-schema.ts`; invalid values stop the server. Feature toggles and other settings live in separate modules: diff --git a/CHANGELOG.md b/CHANGELOG.md index 22da8130..b3008901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed + +- The app no longer fails to load when the browser blocks site data (local storage). UI settings such as the theme, panel widths and editor tabs are then kept only until the page is reloaded. + ## [26.11.0] - 2026-11-20 ## [26.11.0-rc1] - 2026-11-19 diff --git a/e2e/blocked-storage.spec.ts b/e2e/blocked-storage.spec.ts new file mode 100644 index 00000000..75d6df03 --- /dev/null +++ b/e2e/blocked-storage.spec.ts @@ -0,0 +1,64 @@ +import { test, expect } from './support/fixtures.js'; +import { waitForHydration } from './support/helpers'; + +// Browsers that block site data throw a SecurityError on merely reading `localStorage`. The app +// must still hydrate and work, only without persisting UI state. +test.describe('Blocked site data', () => { + test.use({ locale: 'en-US' }); + + let pageErrors: Error[]; + + test.beforeEach(async ({ page }) => { + pageErrors = []; + page.on('pageerror', (err) => pageErrors.push(err)); + await page.addInitScript(() => { + for (const name of ['localStorage', 'sessionStorage']) { + Object.defineProperty(window, name, { + configurable: true, + get() { + throw new DOMException('The operation is insecure.', 'SecurityError'); + } + }); + } + }); + }); + + test.afterEach(() => { + expect(pageErrors.map((e) => e.message)).toEqual([]); + }); + + test('app shell hydrates and the theme toggle works', async ({ page }) => { + // Firefox is slower to hydrate; triple the default timeout. + test.slow(); + await page.goto('/'); + await waitForHydration(page); + + const html = page.locator('html'); + await expect(html).toHaveAttribute('data-theme', /^(light|dark)$/); + const initialTheme = await html.getAttribute('data-theme'); + + await page.getByRole('button', { name: /switch to (light|dark) mode/i }).click(); + await expect(html).not.toHaveAttribute('data-theme', initialTheme ?? ''); + }); + + test('Trino page hydrates and warns that tabs are not saved', async ({ page }) => { + test.slow(); + await page.goto('/trino'); + await waitForHydration(page); + + await expect(page.getByRole('tab')).toHaveCount(1); + await page.getByRole('button', { name: 'New Tab' }).click(); + await expect(page.getByRole('tab')).toHaveCount(2); + await expect( + page.getByRole('alert').filter({ hasText: "Tabs can't be saved in this browser." }) + ).toBeVisible(); + }); + + test('storage page hydrates', async ({ page }) => { + test.slow(); + await page.goto('/storage'); + await waitForHydration(page); + + await expect(page.getByRole('heading', { level: 1 })).toBeVisible(); + }); +}); diff --git a/eslint.config.js b/eslint.config.js index 1b07b31a..bf97b0da 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -175,6 +175,29 @@ export default defineConfig( files: ['src/lib/components/ui/Modal.svelte'], rules: { 'svelte/no-restricted-html-elements': 'off' } }, + { + // Touching Web Storage throws when the browser blocks site data, and a throw during hydration + // takes down the whole app. The helpers in local-storage.ts catch that. + files: ['src/**/*.{ts,svelte}'], + ignores: ['src/lib/client/local-storage.ts', 'src/**/*.{test,spec}.ts', 'src/test/**'], + rules: { + 'no-restricted-globals': [ + 'error', + ...['localStorage', 'sessionStorage'].map((name) => ({ + name, + message: 'Use the helpers in $lib/client/local-storage instead.' + })) + ], + 'no-restricted-properties': [ + 'error', + ...['localStorage', 'sessionStorage'].map((property) => ({ + object: 'window', + property, + message: 'Use the helpers in $lib/client/local-storage instead.' + })) + ] + } + }, { // Generic building blocks: everything comes in through props, so they must not depend on app // state, routing or feature modules (see "Component Layers" in AGENTS.md). diff --git a/messages/de.json b/messages/de.json index 33059d9f..9045676d 100644 --- a/messages/de.json +++ b/messages/de.json @@ -138,7 +138,7 @@ "trino_tab_default_name": "Unbenannt", "trino_tab_rename": "Tab umbenennen", "trino_tab_list": "Abfrage-Tabs", - "trino_tabs_persist_error": "Tab-Inhalt zu groß zum Speichern. Einige Änderungen gehen beim Neuladen möglicherweise verloren.", + "trino_tabs_persist_error": "Tabs können in diesem Browser nicht gespeichert werden. Änderungen gehen beim Neuladen möglicherweise verloren.", "trino_editor_char_limit_reached": "Abfrage überschreitet {limit} Zeichen und wird nicht zwischen Sitzungen gespeichert", "trino_run_at_cursor": "Ausführen", "trino_run_all": "Alle ausführen", diff --git a/messages/en.json b/messages/en.json index 647dbc5e..5a3aa569 100644 --- a/messages/en.json +++ b/messages/en.json @@ -138,7 +138,7 @@ "trino_tab_default_name": "Untitled", "trino_tab_rename": "Rename tab", "trino_tab_list": "Query tabs", - "trino_tabs_persist_error": "Tab content too large to save. Some changes may be lost on reload.", + "trino_tabs_persist_error": "Tabs can't be saved in this browser. Changes may be lost on reload.", "trino_editor_char_limit_reached": "Query exceeds {limit} characters and will not be saved between sessions", "trino_run_at_cursor": "Run", "trino_run_all": "Run all", diff --git a/src/app.html b/src/app.html index ea0df32a..f71ec355 100644 --- a/src/app.html +++ b/src/app.html @@ -6,12 +6,19 @@ diff --git a/src/lib/components/layout/sidebar/Sidebar.svelte b/src/lib/components/layout/sidebar/Sidebar.svelte index 0c12665b..7673fecb 100644 --- a/src/lib/components/layout/sidebar/Sidebar.svelte +++ b/src/lib/components/layout/sidebar/Sidebar.svelte @@ -1,6 +1,5 @@ diff --git a/src/lib/editor/completion/completion-history.ts b/src/lib/editor/completion/completion-history.ts index aaee00e3..f3a0b824 100644 --- a/src/lib/editor/completion/completion-history.ts +++ b/src/lib/editor/completion/completion-history.ts @@ -2,6 +2,9 @@ // localStorage. Items in their kind's list are biased above unused items via // their `sortText` so the user's working vocabulary surfaces to the top. +import { z } from 'zod'; +import { readStorageJson, removeStorage, writeStorage } from '$lib/client/local-storage.js'; + export type HistoryCategory = 'catalogs' | 'schemas' | 'tables' | 'columns' | 'functions' | 'keywords'; @@ -28,18 +31,11 @@ let saveTimer: ReturnType | null = null; function loadHistory(): HistoryStore { if (store) return store; - if (typeof localStorage === 'undefined') { - store = emptyStore(); - return store; - } - try { - const raw = localStorage.getItem(STORAGE_KEY); - if (!raw) { - store = emptyStore(); - return store; - } - const parsed = JSON.parse(raw) as Partial; - const fresh = emptyStore(); + // Only the outer shape is checked here; each category is sanitised below so that one bad list + // does not discard the others. + const parsed = readStorageJson(STORAGE_KEY, z.record(z.string(), z.unknown())); + const fresh = emptyStore(); + if (parsed) { for (const category of Object.keys(fresh) as HistoryCategory[]) { const list = parsed[category]; if (Array.isArray(list)) { @@ -55,23 +51,16 @@ function loadHistory(): HistoryStore { } } } - store = fresh; - } catch { - store = emptyStore(); } + store = fresh; return store; } function scheduleSave(): void { - if (typeof localStorage === 'undefined') return; if (saveTimer) clearTimeout(saveTimer); saveTimer = setTimeout(() => { saveTimer = null; - try { - localStorage.setItem(STORAGE_KEY, JSON.stringify(store)); - } catch { - // localStorage may be unavailable (private mode, quota); silent fail is fine. - } + writeStorage(STORAGE_KEY, JSON.stringify(store)); }, SAVE_DEBOUNCE_MS); } @@ -114,11 +103,5 @@ export function _resetCompletionHistory(): void { clearTimeout(saveTimer); saveTimer = null; } - if (typeof localStorage !== 'undefined') { - try { - localStorage.removeItem(STORAGE_KEY); - } catch { - /* noop */ - } - } + removeStorage(STORAGE_KEY); } diff --git a/src/lib/storage/operations.svelte.spec.ts b/src/lib/storage/operations.svelte.spec.ts index c7ac7592..b1e3b116 100644 --- a/src/lib/storage/operations.svelte.spec.ts +++ b/src/lib/storage/operations.svelte.spec.ts @@ -105,6 +105,36 @@ describe('localStorage persistence', () => { expect(state.operations).toEqual([]); }); + it('keeps every field of an operation across a save and reload', () => { + // `Required` makes this fail to compile when StorageOperation gains a field, and the + // round trip then fails if StorageOperationSchema does not know it (zod strips unknown keys). + const full: Required = { + id: 'op-full', + label: 'Copy: a.txt, b.txt', + // Not 'running', so loading keeps the status as it is. + status: 'error', + type: 'paste', + itemCount: 2, + completedCount: 1, + errorMessage: 'Access denied', + startedAt: 1_000, + completedAt: 2_000, + destPath: 'test-bucket/dest/', + sourceNames: ['a.txt', 'b.txt'], + totalBytes: 300, + completedBytes: 100, + currentFileName: 'b.txt', + fileJobIds: ['job-1', 'job-2'] + }; + localStorage.setItem(OPERATIONS_HISTORY_KEY, JSON.stringify([full])); + + // Load, then save through the real code path by starting another operation. + new OperationsState(makeMockApi(), makeOpts()).startOp('op-new', 'Copy: c.txt', 'paste', 1); + const reloaded = new OperationsState(makeMockApi(), makeOpts()); + + expect(reloaded.operations.find((op) => op.id === 'op-full')).toEqual(full); + }); + it('startOp persists a running operation to localStorage', () => { const state = new OperationsState(makeMockApi(), makeOpts()); diff --git a/src/lib/storage/operations.svelte.ts b/src/lib/storage/operations.svelte.ts index 20956353..466d44f1 100644 --- a/src/lib/storage/operations.svelte.ts +++ b/src/lib/storage/operations.svelte.ts @@ -2,6 +2,8 @@ import { SvelteMap } from 'svelte/reactivity'; import { browser } from '$app/environment'; import type { StorageOperation } from '$lib/storage/types.js'; import type { JobStatus, StorageApi } from './api.js'; +import { loadFromStorage, persistToStorage } from '$lib/client/local-storage.js'; +import { StorageOperationSchema } from './persistence.js'; // ── Page-unloading flag ───────────────────────────────────────────────────── @@ -19,32 +21,18 @@ const MAX_HISTORY_ENTRIES = 30; const JOB_START_GRACE_MS = 60_000; function loadPersistedOperations(): StorageOperation[] { - if (!browser) return []; - try { - const raw = localStorage.getItem(OPERATIONS_HISTORY_KEY); - if (!raw) return []; - const ops = JSON.parse(raw) as StorageOperation[]; - if (!Array.isArray(ops)) return []; - return ops.map((op) => - op.status === 'running' - ? { ...op, status: 'interrupted' as const, completedAt: op.completedAt ?? Date.now() } - : op - ); - } catch { - return []; - } + return loadFromStorage(OPERATIONS_HISTORY_KEY, StorageOperationSchema).map((op) => + op.status === 'running' + ? { ...op, status: 'interrupted' as const, completedAt: op.completedAt ?? Date.now() } + : op + ); } function saveOperationsToStorage(ops: StorageOperation[]): void { - if (!browser) return; - try { - const history = ops.filter((op) => op.status !== 'running').slice(-MAX_HISTORY_ENTRIES); - const running = ops.filter((op) => op.status === 'running'); - const toSave = [...running, ...history].slice(-MAX_HISTORY_ENTRIES); - localStorage.setItem(OPERATIONS_HISTORY_KEY, JSON.stringify(toSave)); - } catch { - // Best effort. - } + const history = ops.filter((op) => op.status !== 'running').slice(-MAX_HISTORY_ENTRIES); + const running = ops.filter((op) => op.status === 'running'); + const toSave = [...running, ...history].slice(-MAX_HISTORY_ENTRIES); + persistToStorage(OPERATIONS_HISTORY_KEY, toSave); } // ── OperationsState ───────────────────────────────────────────────────────── diff --git a/src/lib/storage/persistence.ts b/src/lib/storage/persistence.ts index 9fa63276..bb69ef1a 100644 --- a/src/lib/storage/persistence.ts +++ b/src/lib/storage/persistence.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import type { PinnedLocation, RecentFile, RecentLocation } from './types.js'; +import type { PinnedLocation, RecentFile, RecentLocation, StorageOperation } from './types.js'; // ── localStorage keys ──────────────────────────────────────────────────────── @@ -30,3 +30,38 @@ export const RecentLocationSchema: z.ZodType = z.object({ visitedAt: z.string(), connectionId: z.string() }); + +export const PersistedTabsStateSchema = z.object({ + tabs: z.array( + z.object({ + id: z.string(), + label: z.string(), + bucket: z.string(), + prefix: z.string(), + connection: z.string().optional() + }) + ), + activeTabId: z.string(), + /** Fingerprint of the connection that saved these tabs. */ + connectionId: z.string().nullable().optional() +}); + +export type PersistedTabsState = z.infer; + +export const StorageOperationSchema: z.ZodType = z.object({ + id: z.string(), + label: z.string(), + status: z.enum(['running', 'done', 'error', 'cancelled', 'interrupted', 'unknown']), + type: z.enum(['paste', 'move', 'rename', 'delete', 'download']), + itemCount: z.number(), + completedCount: z.number(), + errorMessage: z.string().optional(), + startedAt: z.number(), + completedAt: z.number().optional(), + destPath: z.string().optional(), + sourceNames: z.array(z.string()).optional(), + totalBytes: z.number(), + completedBytes: z.number(), + currentFileName: z.string().optional(), + fileJobIds: z.array(z.string()).optional() +}); diff --git a/src/lib/storage/tabs.svelte.spec.ts b/src/lib/storage/tabs.svelte.spec.ts index 2eef8078..97e94047 100644 --- a/src/lib/storage/tabs.svelte.spec.ts +++ b/src/lib/storage/tabs.svelte.spec.ts @@ -1,5 +1,6 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; -import { TabsState, type PersistedTabsState } from '$lib/storage/tabs.svelte.js'; +import { TabsState } from '$lib/storage/tabs.svelte.js'; +import type { PersistedTabsState } from '$lib/storage/persistence.js'; import { StorageState } from '$lib/storage/state.svelte.js'; import { LS_TABS } from '$lib/storage/persistence.js'; import { SvelteSet } from 'svelte/reactivity'; diff --git a/src/lib/storage/tabs.svelte.ts b/src/lib/storage/tabs.svelte.ts index 6dc364b7..03181057 100644 --- a/src/lib/storage/tabs.svelte.ts +++ b/src/lib/storage/tabs.svelte.ts @@ -3,7 +3,8 @@ import { SvelteSet } from 'svelte/reactivity'; import type { StoragePage } from '$lib/storage/types.js'; import type { PageSize } from '$lib/types/pagination.js'; import type { StorageState } from './state.svelte.js'; -import { LS_TABS } from './persistence.js'; +import { LS_TABS, PersistedTabsStateSchema, type PersistedTabsState } from './persistence.js'; +import { readStorageJson, removeStorage, writeStorage } from '$lib/client/local-storage.js'; import { keyToName, parentPrefix } from './utils.js'; // ── Tab data ───────────────────────────────────────────────────────────────── @@ -38,23 +39,6 @@ export interface Tab { snapshot: TabSnapshot; } -// ── Persistence schema ──────────────────────────────────────────────────────── - -interface PersistedTab { - id: string; - label: string; - bucket: string; - prefix: string; - connection?: string; -} - -export interface PersistedTabsState { - tabs: PersistedTab[]; - activeTabId: string; - /** Fingerprint of the connection that saved these tabs. */ - connectionId?: string | null; -} - // ── Internal helpers ────────────────────────────────────────────────────────── const EMPTY_PAGE: StoragePage = { objects: [], hasNextPage: false, currentPage: 1, pageSize: 25 }; @@ -167,27 +151,20 @@ export class TabsState { activeTabId: this.activeTabId ?? '', connectionId: this.connectionId }; - localStorage.setItem(LS_TABS, JSON.stringify(data)); + writeStorage(LS_TABS, JSON.stringify(data)); } /** Reads persisted tab state from localStorage without modifying any state. * Returns null if nothing is saved or the saved * state belongs to a different connection. */ peekPersistedTabs(): PersistedTabsState | null { - if (!browser) return null; - try { - const raw = localStorage.getItem(LS_TABS); - if (!raw) return null; - const data = JSON.parse(raw) as PersistedTabsState; - if (!Array.isArray(data.tabs) || data.tabs.length === 0) return null; - if (data.connectionId === undefined) return null; - if (data.connectionId !== this.connectionId) { - return null; - } - return data; - } catch { + const data = readStorageJson(LS_TABS, PersistedTabsStateSchema); + if (!data || data.tabs.length === 0) return null; + if (data.connectionId === undefined) return null; + if (data.connectionId !== this.connectionId) { return null; } + return data; } /** Restores tabs from a previously peeked snapshot. Creates stub tabs for @@ -248,7 +225,7 @@ export class TabsState { /** Removes the persisted tabs entry from localStorage. */ clearPersistedTabs(): void { - if (browser) localStorage.removeItem(LS_TABS); + removeStorage(LS_TABS); } // ── Tab operations ─────────────────────────────────────────────────────── diff --git a/src/lib/stores/tab-store.svelte.ts b/src/lib/stores/tab-store.svelte.ts index 162fb8cf..ed98135b 100644 --- a/src/lib/stores/tab-store.svelte.ts +++ b/src/lib/stores/tab-store.svelte.ts @@ -1,6 +1,12 @@ import { browser } from '$app/environment'; import { z } from 'zod'; import * as m from '$lib/paraglide/messages.js'; +import { + readStorage, + readStorageJson, + removeStorage, + writeStorage +} from '$lib/client/local-storage.js'; const MAX_TABS = 8; const INDEX_KEY = 'trino_tabs_index'; @@ -51,23 +57,11 @@ function makeTab(sql: string = DEFAULT_SQL): TabState { // --------------------------------------------------------------------------- function readIndex(): IndexData | null { - try { - const raw = localStorage.getItem(INDEX_KEY); - if (!raw) return null; - const parsed = IndexDataSchema.safeParse(JSON.parse(raw)); - if (parsed.success) return parsed.data; - } catch { - // Ignore corrupt data. - } - return null; + return readStorageJson(INDEX_KEY, IndexDataSchema); } function readTabSql(id: string): string { - try { - return localStorage.getItem(TAB_KEY_PREFIX + id) ?? DEFAULT_SQL; - } catch { - return DEFAULT_SQL; - } + return readStorage(TAB_KEY_PREFIX + id) ?? DEFAULT_SQL; } /** Load tabs from the persisted index and per-tab SQL entries. */ @@ -99,35 +93,20 @@ function createDefaultState(): { tabs: TabState[]; activeTabId: string } { function persistIndex(tabs: TabState[], activeTabId: string): boolean { if (!browser) return true; - try { - const data: IndexData = { - tabs: tabs.map((t) => ({ id: t.id, label: t.label, createdAt: t.createdAt })), - activeTabId - }; - localStorage.setItem(INDEX_KEY, JSON.stringify(data)); - return true; - } catch { - return false; - } + const data: IndexData = { + tabs: tabs.map((t) => ({ id: t.id, label: t.label, createdAt: t.createdAt })), + activeTabId + }; + return writeStorage(INDEX_KEY, JSON.stringify(data)); } function persistTabSql(id: string, sql: string): boolean { if (!browser) return true; - try { - localStorage.setItem(TAB_KEY_PREFIX + id, sql); - return true; - } catch { - return false; - } + return writeStorage(TAB_KEY_PREFIX + id, sql); } function removeTabSql(id: string) { - if (!browser) return; - try { - localStorage.removeItem(TAB_KEY_PREFIX + id); - } catch { - // Best effort. - } + removeStorage(TAB_KEY_PREFIX + id); } // --------------------------------------------------------------------------- diff --git a/src/lib/types/pagination.ts b/src/lib/types/pagination.ts index f1e8cf89..b9c9393a 100644 --- a/src/lib/types/pagination.ts +++ b/src/lib/types/pagination.ts @@ -1,5 +1,5 @@ -import { browser } from '$app/environment'; import { allowedPageSizes, defaultPageSize } from '$lib/client/config.js'; +import { readStorage } from '$lib/client/local-storage.js'; export type PageSize = number; @@ -8,7 +8,6 @@ export function isPageSize(n: number): n is PageSize { } export function initPageSize(storageKey: string): PageSize { - if (!browser) return defaultPageSize; - const stored = parseInt(localStorage.getItem(storageKey) ?? '', 10); + const stored = parseInt(readStorage(storageKey) ?? '', 10); return isPageSize(stored) ? stored : defaultPageSize; } diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 3d1f1a54..e1b0ec5d 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -1,5 +1,4 @@