Files
hermes-config/skills/self-hosting/shop-pro-quote/references/settings-save-bug.md
T
2026-07-12 10:17:17 -04:00

1.2 KiB

Settings Save/Load Bug

The settings PocketBase collection has schema: id, userId, name, data (JSON). All business settings go inside the data JSON field.

The Bug

Settings were saved as direct fields (businessName, businessAddress, etc.) which PocketBase silently drops because they don't match the collection schema. On reload, settings were read from those same direct fields, which were always empty.

Fix in Settings.tsx

Save — wrap in { data: {...} }:

// ❌ Before — fields silently dropped:
await pb.collection('settings').create({ userId, ...DEFAULT_SETTINGS });
await pb.collection('settings').update(record.id, s);

// ✅ After — stored in data JSON field:
await pb.collection('settings').create({ userId, name: 'businessSettings', data: DEFAULT_SETTINGS });
await pb.collection('settings').update(record.id, { data: s });

Load — read from r.data with fallback to direct fields:

const d = (r.data as Record<string, unknown>) || {};
businessName: (d.businessName as string) || (r.businessName as string) || '',

The fallback preserves backward compatibility with any records that may have been saved at the top level.