Fix unit/product kind enums serializing as integers
Two bugs found during exploratory testing: 1. UnitKind and ProductKind enums were serialized as 0/1 instead of "Global"/"Family" because no global JSON converter was registered. Added JsonStringEnumConverter to ConfigureHttpJsonOptions so all enum responses (kind, category) serialize as strings. This also fixes UnitCategory coming back as a number. 2. units.svelte.ts triggered a Svelte 5 state_unsafe_mutation error because the `all` getter called load() (which mutates $state) from inside a $derived expression in QuantityInput. Wrapped the load() call in untrack() so the side-effect runs outside the reactive tracking context. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { untrack } from 'svelte';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export type UnitKind = 'Global' | 'Family';
|
||||
@@ -24,7 +25,10 @@ let error = $state<string | null>(null);
|
||||
export const units = {
|
||||
get all() {
|
||||
if (cache === null && !loading) {
|
||||
void load();
|
||||
// Use untrack so the load() side-effect (which mutates $state) is
|
||||
// not flagged as an illegal mutation when this getter is read inside
|
||||
// a $derived expression.
|
||||
untrack(() => void load());
|
||||
}
|
||||
return cache ?? [];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user