Skip to content

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

fix: ignore stale General settings loads (#5480)

[._.]/ Adam Eivy6a87dc6d7d1f
diff --git a/client/src/components/settings/GeneralTab.jsx b/client/src/components/settings/GeneralTab.jsx
index 20c7d4b123..e76b1a12c3 100644
--- a/client/src/components/settings/GeneralTab.jsx
+++ b/client/src/components/settings/GeneralTab.jsx
@@ -39,8 +39,10 @@ export function GeneralTab() {
const routeGuard = useUnsavedChangesGuard(dirty);
useEffect(() => {
+ let current = true;
getSettings({ silent: true })
.then(settings => {
+ if (!current) return;
const nextTimezone = settings?.timezone || '';
const nextLat = settings?.location?.lat != null ? String(settings.location.lat) : '';
const nextLon = settings?.location?.lon != null ? String(settings.location.lon) : '';
@@ -51,6 +53,7 @@ export function GeneralTab() {
setSavedLocation({ lat: nextLat, lon: nextLon });
})
.catch(() => {
+ if (!current) return;
// The empty fields remain usable after a failed load, so treat the
// displayed fallback as the baseline instead of leaving edits outside
// dirty tracking.
@@ -58,7 +61,10 @@ export function GeneralTab() {
setSavedLocation({ lat: '', lon: '' });
toast.error('Failed to load settings');
})
- .finally(() => setLoading(false));
+ .finally(() => {
+ if (current) setLoading(false);
+ });
+ return () => { current = false; };
}, []);
const handleSaveLocation = async () => {
diff --git a/client/src/components/settings/GeneralTab.test.jsx b/client/src/components/settings/GeneralTab.test.jsx
index b99997c6bd..c22277c8bd 100644
--- a/client/src/components/settings/GeneralTab.test.jsx
+++ b/client/src/components/settings/GeneralTab.test.jsx
@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { StrictMode } from 'react';
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { createMemoryRouter, RouterProvider } from 'react-router';
@@ -45,8 +46,12 @@ const renderTab = async ({ expectedTimezone = 'UTC' } = {}) => {
const navigate = (router, to) => act(async () => { await router.navigate(to); });
const deferred = () => {
let resolve;
- const promise = new Promise((settle) => { resolve = settle; });
- return { promise, resolve };
+ let reject;
+ const promise = new Promise((settle, fail) => {
+ resolve = settle;
+ reject = fail;
+ });
+ return { promise, resolve, reject };
};
beforeEach(() => {
@@ -68,6 +73,26 @@ describe('GeneralTab unsaved changes', () => {
expect(screen.getByText(CONFIRM)).toBeInTheDocument();
});
+ it('ignores an older StrictMode load failure after the current load succeeds', async () => {
+ const olderLoad = deferred();
+ const currentLoad = deferred();
+ getSettings
+ .mockReturnValueOnce(olderLoad.promise)
+ .mockReturnValueOnce(currentLoad.promise);
+ const router = createMemoryRouter([
+ { path: '/settings/general', element: <GeneralTab /> },
+ ], { initialEntries: ['/settings/general'] });
+ render(<StrictMode><RouterProvider router={router} /></StrictMode>);
+
+ await act(async () => { currentLoad.resolve(SETTINGS); });
+ expect(await screen.findByDisplayValue('UTC')).toBeInTheDocument();
+ await act(async () => { olderLoad.reject(new Error('stale settings request')); });
+
+ expect(screen.queryByText('Unsaved changes')).toBeNull();
+ expect(screen.getByLabelText('Timezone (IANA)')).toHaveValue('UTC');
+ expect(screen.getByLabelText('Latitude (-90 to 90)')).toHaveValue(String(SETTINGS.location.lat));
+ });
+
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');