Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: close unsaved settings guard races (#5480)
[._.]/ Adam Eivy36bb17aaf910
diff --git a/client/src/components/settings/GeneralTab.jsx b/client/src/components/settings/GeneralTab.jsxindex 362aec0455..753b5f07b1 100644--- a/client/src/components/settings/GeneralTab.jsx+++ b/client/src/components/settings/GeneralTab.jsx@@ -34,6 +34,8 @@ export function GeneralTab() {const locationDirty = savedLocation !== null&& (lat !== savedLocation.lat || lon !== savedLocation.lon);const dirty = timezoneDirty || locationDirty;+ const hasDiscardableChanges = (timezoneDirty && !saving)+ || (locationDirty && !savingLocation);const routeGuard = useUnsavedChangesGuard(dirty);useEffect(() => {@@ -48,7 +50,14 @@ export function GeneralTab() {setLon(nextLon);setSavedLocation({ lat: nextLat, lon: nextLon });})- .catch(() => toast.error('Failed to load settings'))+ .catch(() => {+ // The empty fields remain usable after a failed load, so treat the+ // displayed fallback as the baseline instead of leaving edits outside+ // dirty tracking.+ setSavedTimezone('');+ setSavedLocation({ lat: '', lon: '' });+ toast.error('Failed to load settings');+ }).finally(() => setLoading(false));}, []);@@ -133,7 +142,7 @@ export function GeneralTab() {<div className="space-y-6"><UnsavedChangesConfirmguard={routeGuard}- when={!saving && !savingLocation}+ when={hasDiscardableChanges}question="Discard your unsaved General settings changes?"label="Discard unsaved General settings changes"onDiscard={routeGuard.proceed}@@ -158,8 +167,9 @@ export function GeneralTab() {type="text"value={timezone}onChange={e => setTimezone(e.target.value)}+ disabled={saving}placeholder={detectedTz}- className="w-full sm:flex-1 sm:max-w-xs min-w-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"+ className="w-full sm:flex-1 sm:max-w-xs min-w-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm disabled:opacity-50"list="tz-list"/><button@@ -214,8 +224,9 @@ export function GeneralTab() {inputMode="decimal"value={lat}onChange={e => setLat(e.target.value)}+ disabled={savingLocation}placeholder="37.7749"- className="w-full min-w-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"+ className="w-full min-w-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm disabled:opacity-50"/></FormField><FormField@@ -229,8 +240,9 @@ export function GeneralTab() {inputMode="decimal"value={lon}onChange={e => setLon(e.target.value)}+ disabled={savingLocation}placeholder="-122.4194"- className="w-full min-w-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"+ className="w-full min-w-0 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm disabled:opacity-50"/></FormField><buttondiff --git a/client/src/components/settings/GeneralTab.test.jsx b/client/src/components/settings/GeneralTab.test.jsxindex cc67a58cd4..8720b70a49 100644--- a/client/src/components/settings/GeneralTab.test.jsx+++ b/client/src/components/settings/GeneralTab.test.jsx@@ -28,17 +28,26 @@ const CONFIRM = 'Discard your unsaved General settings changes?';const timezoneCard = () => screen.getByRole('heading', { name: 'Timezone' }).parentElement;const locationCard = () => screen.getByRole('heading', { name: 'Location' }).parentElement;-const renderTab = async () => {+const renderTab = async ({ expectedTimezone = 'UTC' } = {}) => {const router = createMemoryRouter([{ path: '/settings/general', element: <GeneralTab /> },{ path: '/settings/security', element: <div>Security settings</div> },], { initialEntries: ['/settings/general'] });render(<RouterProvider router={router} />);- await screen.findByDisplayValue('UTC');+ if (expectedTimezone === null) {+ await screen.findByLabelText('Timezone (IANA)');+ } else {+ await screen.findByDisplayValue(expectedTimezone);+ }return router;};const navigate = (router, to) => act(async () => { await router.navigate(to); });+const deferred = () => {+ let resolve;+ const promise = new Promise((settle) => { resolve = settle; });+ return { promise, resolve };+};beforeEach(() => {vi.clearAllMocks();@@ -47,6 +56,18 @@ beforeEach(() => {});describe('GeneralTab unsaved changes', () => {+ it('guards edits made against the displayed fallback after loading fails', async () => {+ getSettings.mockRejectedValueOnce(new Error('settings offline'));+ const router = await renderTab({ expectedTimezone: null });+ fireEvent.change(screen.getByLabelText('Timezone (IANA)'), {+ target: { value: 'America/New_York' },+ });++ expect(within(timezoneCard()).getByText('Unsaved changes')).toBeInTheDocument();+ await navigate(router, '/settings/security');+ expect(screen.getByText(CONFIRM)).toBeInTheDocument();+ });+it('marks each edited section dirty, arms beforeunload, and clears when values are restored', async () => {const add = vi.spyOn(window, 'addEventListener');const remove = vi.spyOn(window, 'removeEventListener');@@ -140,6 +161,33 @@ describe('GeneralTab unsaved changes', () => {expect(screen.queryByText('Unsaved changes')).toBeNull();});+ it('locks each section during its save without hiding another section\'s discard prompt', async () => {+ const timezoneSave = deferred();+ const locationSave = deferred();+ updateSettings+ .mockReturnValueOnce(timezoneSave.promise)+ .mockReturnValueOnce(locationSave.promise);+ const router = await renderTab();+ const timezoneInput = screen.getByLabelText('Timezone (IANA)');+ const latitudeInput = screen.getByLabelText('Latitude (-90 to 90)');+ const longitudeInput = screen.getByLabelText('Longitude (-180 to 180)');+ fireEvent.change(timezoneInput, { target: { value: 'America/New_York' } });+ fireEvent.change(latitudeInput, { target: { value: '40.7128' } });++ fireEvent.click(within(timezoneCard()).getByRole('button', { name: 'Save' }));+ expect(timezoneInput).toBeDisabled();+ expect(latitudeInput).not.toBeDisabled();+ await navigate(router, '/settings/security');+ expect(screen.getByText(CONFIRM)).toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Keep editing' }));++ await act(async () => { timezoneSave.resolve({}); });+ fireEvent.click(within(locationCard()).getByRole('button', { name: 'Save' }));+ expect(latitudeInput).toBeDisabled();+ expect(longitudeInput).toBeDisabled();+ await act(async () => { locationSave.resolve({}); });+ });+it('keeps a failed timezone save dirty and guarded', async () => {updateSettings.mockRejectedValueOnce(new Error('timezone offline'));const router = await renderTab();