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: isolate catalog editor state for each ingredient visit

Adam Eivy046ffe3ea84d
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsx
index 4318c1db86..3b7f70467c 100644
--- a/client/src/pages/CatalogIngredient.jsx
+++ b/client/src/pages/CatalogIngredient.jsx
@@ -164,7 +164,15 @@ function ingredientPayload(value) {
}
export default function CatalogIngredient() {
+ const { id } = useParams();
+ // One owner per ingredient visit: late mutations and child-local drafts must
+ // never migrate to another record. Tabs keep the same owner and unsaved form.
+ return <IngredientEditor key={id} />;
+}
+
+function IngredientEditor() {
const { id, tab: tabParam } = useParams();
+ const mountedRef = useMounted();
const activeVisitRef = useRef({ id, generation: 0 });
if (activeVisitRef.current.id !== id) {
activeVisitRef.current = { id, generation: activeVisitRef.current.generation + 1 };
@@ -546,7 +554,7 @@ export default function CatalogIngredient() {
const ok = await deleteCatalogIngredient(record.id, { silent: true })
.then(() => true)
.catch((err) => { toast.error(err?.message || 'Delete failed'); return false; });
- if (ok) {
+ if (ok && mountedRef.current) {
toast.success('Deleted');
navigate(backPath);
}
diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsx
index c807a18b76..023158cd98 100644
--- a/client/src/pages/CatalogIngredient.test.jsx
+++ b/client/src/pages/CatalogIngredient.test.jsx
@@ -256,6 +256,25 @@ describe('CatalogIngredient — character sheet', () => {
expect(uploadCatalogIngredientMediaFile).not.toHaveBeenCalled();
});
+ it('keeps the new ingredient draft when an earlier restore completes', async () => {
+ let finishRestore;
+ restoreCatalogIngredientRevision.mockImplementationOnce(() => new Promise(resolve => { finishRestore = resolve; }));
+ getCatalogIngredientDetails.mockImplementation(async id => ({
+ ...detailsOf({ ...CHAR_FIXTURE, id, name: id === 'cat-chr-1' ? 'First ingredient' : 'Second ingredient' }),
+ revisions: [{ id: 'latest', name: 'Current' }, { id: 'old', name: 'Earlier' }],
+ }));
+ const { router } = await renderPage();
+ fireEvent.click(await screen.findByRole('button', { name: 'Restore', exact: true }));
+ fireEvent.click(screen.getByRole('button', { name: 'Restore', exact: true }));
+ await waitFor(() => expect(restoreCatalogIngredientRevision).toHaveBeenCalledTimes(1));
+ await act(async () => router.navigate('/catalog/character/cat-chr-2'));
+ await screen.findByDisplayValue('Second ingredient');
+ fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Second draft' } });
+ await act(async () => finishRestore({ ...CHAR_FIXTURE, name: 'Restored first ingredient' }));
+ expect(screen.getByLabelText('Name')).toHaveValue('Second draft');
+ expect(screen.getByText('Unsaved changes')).toBeInTheDocument();
+ });
+
it('keeps revision restore confirmation open when restore fails', async () => {
getCatalogIngredientDetails.mockImplementation(async () => ({
...detailsOf(CHAR_FIXTURE),