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: ignore stale catalog saves across repeat visits (#8524)
[._.]/ Adam Eivy041f9257a979
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsxindex edc5af0477..dd2d4f4971 100644--- a/client/src/pages/CatalogIngredient.jsx+++ b/client/src/pages/CatalogIngredient.jsx@@ -127,8 +127,10 @@ function ingredientPayload(value) {export default function CatalogIngredient() {const { id } = useParams();- const activeIdRef = useRef(id);- activeIdRef.current = id;+ const activeVisitRef = useRef({ id, generation: 0 });+ if (activeVisitRef.current.id !== id) {+ activeVisitRef.current = { id, generation: activeVisitRef.current.generation + 1 };+ }const navigate = useNavigate();// Merged type registry (system + user-defined). Falls back synchronously to// the static built-ins so the editor renders before the fetch resolves.@@ -331,6 +333,7 @@ export default function CatalogIngredient() {const handleSave = async () => {if (!record) return;const submittedId = record.id;+ const submittedGeneration = activeVisitRef.current.generation;const submittedName = name;const submittedTags = tags;const submittedPayload = payload;@@ -348,7 +351,9 @@ export default function CatalogIngredient() {toast.error(err?.message || 'Save failed');return null;});- if (activeIdRef.current !== submittedId) return;+ const isCurrentVisit = () => activeVisitRef.current.id === submittedId+ && activeVisitRef.current.generation === submittedGeneration;+ if (!isCurrentVisit()) return;setSaving(false);if (!updated) return;const persistedName = typeof updated.name === 'string' ? updated.name : trimmedName;@@ -356,14 +361,14 @@ export default function CatalogIngredient() {const persistedPayload = Object.hasOwn(updated, 'payload')? ingredientPayload(updated.payload): ingredientPayload(submittedPayload);- setRecord((prev) => prev?.id === submittedId ? ({+ setRecord((prev) => isCurrentVisit() && prev?.id === submittedId ? ({...prev, ...updated, name: persistedName, tags: persistedTags, payload: persistedPayload,}) : prev);- setName((current) => activeIdRef.current === submittedId && current === submittedName ? persistedName : current);+ setName((current) => isCurrentVisit() && current === submittedName ? persistedName : current);// The server normalizes tags through the canonical table (casing/whitespace// collapse), so reflect the persisted set back into the chips.- setTags((current) => activeIdRef.current === submittedId && sameValue(current, submittedTags) ? persistedTags : current);- setPayload((current) => activeIdRef.current === submittedId && sameValue(current, submittedPayload) ? { ...persistedPayload } : current);+ setTags((current) => isCurrentVisit() && sameValue(current, submittedTags) ? persistedTags : current);+ setPayload((current) => isCurrentVisit() && sameValue(current, submittedPayload) ? { ...persistedPayload } : current);toast.success('Saved');refreshRevisions();};diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsxindex 7d62898bc0..337a4a28ff 100644--- a/client/src/pages/CatalogIngredient.test.jsx+++ b/client/src/pages/CatalogIngredient.test.jsx@@ -325,7 +325,7 @@ describe('CatalogIngredient — character sheet', () => {expect(screen.getByText('Unsaved changes')).toBeTruthy();});- it('ignores a save response after switching to another record', async () => {+ it('ignores a save response after switching records and returning', async () => {let finishSave;updateCatalogIngredient.mockImplementationOnce(() => new Promise((resolve) => { finishSave = resolve; }));getCatalogIngredientDetails.mockImplementation(async (id) => detailsOf({@@ -337,9 +337,11 @@ describe('CatalogIngredient — character sheet', () => {await waitFor(() => expect(updateCatalogIngredient).toHaveBeenCalledTimes(1));await act(async () => router.navigate('/catalog/character/cat-chr-2'));await screen.findByDisplayValue('Second ingredient');+ await act(async () => router.navigate('/catalog/character/cat-chr-1'));+ await screen.findByDisplayValue('First ingredient');await act(async () => finishSave({ ...CHAR_FIXTURE, name: 'Stale response' }));- expect(screen.getByLabelText('Name').value).toBe('Second ingredient');+ expect(screen.getByLabelText('Name').value).toBe('First ingredient');expect(screen.queryByText('Stale response')).toBeNull();});});