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: mint ImageGen reference preview URLs outside the state updater (#5722)
Adam Eivy318f6a928762
diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsxindex 1ae3640fd6..4d00418253 100644--- a/client/src/pages/ImageGen.jsx+++ b/client/src/pages/ImageGen.jsx@@ -584,10 +584,15 @@ export default function ImageGen() {if (!raw) return;const file = await normalizeImageOrientation(raw);if (!mountedRef.current) return;+ // Mint the url OUTSIDE the updater. StrictMode invokes a functional updater+ // twice in dev, and a url created inside it on the discarded pass is never+ // stored — so it can never be revoked. (The revoke stays inside, where it+ // can read the authoritative `prev`; revoking twice is a no-op.)+ const previewUrl = URL.createObjectURL(file);setReferenceImages((prev) => {const next = [...prev];revokeIfBlob(next[slotIndex]?.previewUrl);- next[slotIndex] = { file, previewUrl: URL.createObjectURL(file), strength: next[slotIndex]?.strength ?? 1.0 };+ next[slotIndex] = { file, previewUrl, strength: next[slotIndex]?.strength ?? 1.0 };return next;});};diff --git a/client/src/pages/ImageGen.objectUrls.test.jsx b/client/src/pages/ImageGen.objectUrls.test.jsxindex deb05e5bf0..b9b9cc5f14 100644--- a/client/src/pages/ImageGen.objectUrls.test.jsx+++ b/client/src/pages/ImageGen.objectUrls.test.jsx@@ -1,5 +1,6 @@import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { StrictMode } from 'react';import { MemoryRouter } from 'react-router';// Codex is i2i-capable and declares no input-image cap, so the form offers the@@ -102,14 +103,15 @@ vi.mock('../components/imageGen/LoraPicker', () => ({ default: () => null }));const { default: ImageGen } = await import('./ImageGen.jsx');-const mount = async () => {+const mount = async ({ strict = false } = {}) => {+ const tree = (+ <MemoryRouter initialEntries={['/media/image']}>+ <ImageGen />+ </MemoryRouter>+ );let result;await act(async () => {- result = render(- <MemoryRouter initialEntries={['/media/image']}>- <ImageGen />- </MemoryRouter>,- );+ result = render(strict ? <StrictMode>{tree}</StrictMode> : tree);});return result;};@@ -228,6 +230,22 @@ describe('ImageGen object-URL lifecycle', () => {expect(screen.getByTestId('ref-url-0')).toHaveTextContent(secondRef);});+ // The app renders under StrictMode (client/src/main.jsx), which invokes a+ // functional state updater TWICE in dev. A url minted inside the updater is+ // created on both passes but only one is kept, so the other is unreachable+ // and can never be revoked — a leak on every single reference pick.+ it('mints exactly one url per pick under StrictMode', async () => {+ const { unmount } = await mount({ strict: true });+ await click('pick-init');+ await click('pick-ref-0');++ await waitFor(() => expect(screen.getByTestId('ref-url-0')).not.toHaveTextContent(''));+ expect(state.created).toHaveLength(2);++ await act(async () => { unmount(); });+ expect(liveUrls()).toEqual([]);+ });+// Clearing reclaims immediately, and the later unmount must not re-revoke a// url the clear already released.it('revokes on clear and does not revoke again at unmount', async () => {