fix: replace $effect with onMount for initial data load

$effect re-runs on any reactive state change — loadData/loadConfig both
write state, creating an infinite loop that hung the page under load.
This commit is contained in:
Falkan
2026-03-18 20:18:30 -04:00
parent b020b74c31
commit 4c2fe9b3ad
2 changed files with 5 additions and 3 deletions

View File

@@ -117,7 +117,9 @@
"id": "another-group", "id": "another-group",
"label": "Another Group", "label": "Another Group",
"baseUnitId": "", "baseUnitId": "",
"toUniversal": 1 "toUniversal": 1,
"alwaysShowLabel": false,
"hidden": true
} }
] ]
} }

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { getContext } from 'svelte'; import { getContext, onMount } from 'svelte';
import type { Unit, Group, UnitsData } from '$lib/types'; import type { Unit, Group, UnitsData } from '$lib/types';
const adminPath = getContext<string>('adminPath') ?? 'admin'; const adminPath = getContext<string>('adminPath') ?? 'admin';
@@ -239,7 +239,7 @@
expandedGroups = new Set([...expandedGroups, ...groups.map((g) => g.id)]); expandedGroups = new Set([...expandedGroups, ...groups.map((g) => g.id)]);
} }
$effect(() => { loadData(); loadConfig(); }); onMount(() => { loadData(); loadConfig(); });
async function extractError(res: Response, fallback: string): Promise<string> { async function extractError(res: Response, fallback: string): Promise<string> {
const body = await res.json().catch(() => ({})); const body = await res.json().catch(() => ({}));