fix(cospend): avoid localStorage at module init on list page
CI / update (push) Successful in 3m56s

The store-picker read localStorage at component init, which crashed
SSR on full-page loads of /cospend/list with 'localStorage.getItem is
not a function'. Deferred the read to onMount and wrapped writes in
try/catch.
This commit is contained in:
2026-04-21 16:50:50 +02:00
parent 5b35c9e63b
commit c99442b54b
2 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "homepage",
"version": "1.43.0",
"version": "1.43.1",
"private": true,
"type": "module",
"scripts": {
@@ -61,14 +61,12 @@
};
const STORE_NAMES = Object.keys(STORE_PRESETS);
let selectedStore = $state(
(typeof localStorage !== 'undefined' && localStorage.getItem('shopping-store')) || STORE_NAMES[0]
);
let selectedStore = $state(STORE_NAMES[0]);
let categoryOrder = $derived(STORE_PRESETS[selectedStore] || STORE_PRESETS[STORE_NAMES[0]]);
function setStore(name) {
selectedStore = name;
localStorage.setItem('shopping-store', name);
try { localStorage.setItem('shopping-store', name); } catch { /* ignore */ }
}
let newItemName = $state('');
@@ -149,6 +147,11 @@
let totalCount = $derived(sync.items.length);
onMount(() => {
try {
const saved = localStorage.getItem('shopping-store');
if (saved && STORE_PRESETS[saved]) selectedStore = saved;
} catch { /* ignore */ }
if (data.initialList) {
sync.connect(shareToken);
} else {