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: drop a gallery-picker upload that lands after its modal was dismissed (#4127)
[._.]/ Adam Eivy380eea3cd428
diff --git a/client/src/components/imageGen/GalleryImagePicker.jsx b/client/src/components/imageGen/GalleryImagePicker.jsxindex 102570a134..237b02d5ec 100644--- a/client/src/components/imageGen/GalleryImagePicker.jsx+++ b/client/src/components/imageGen/GalleryImagePicker.jsx@@ -18,7 +18,7 @@//// Local gallery only — no external/web search (deliberate, see plan).-import { useEffect, useMemo, useState } from 'react';+import { useEffect, useMemo, useRef, useState } from 'react';import { Search, X, RefreshCw, Upload } from 'lucide-react';import Modal from '../ui/Modal';import FilePickerButton from '../ui/FilePickerButton';@@ -67,6 +67,10 @@ export default function GalleryImagePicker({// '' = All. Otherwise `uni:<id>` or `col:<id>`.const [scope, setScope] = useState('');const [type, setType] = useState('');+ // Bumped on every open/close transition, so an async upload can tell whether+ // the picker session it started in is still the current one.+ const sessionRef = useRef(0);+ useEffect(() => { sessionRef.current += 1; }, [open]);// Fetch the gallery each time the picker opens so newly generated images show// up without a page reload. Reset the search on close so a re-open starts clean.@@ -201,6 +205,7 @@ export default function GalleryImagePicker({// file dialog. `maxBytes` lets a host keep a tighter product cap than the wire limit.const invalid = validateImageFile(file, maxBytes);if (invalid) { toast.error(invalid); return; }+ const session = sessionRef.current;setUploading(true);const base64 = await readFileAsBase64(file).catch(() => null);if (!base64) { setUploading(false); toast.error(`Failed to read ${file.name}`); return; }@@ -210,6 +215,11 @@ export default function GalleryImagePicker({});setUploading(false);if (!saved?.filename) return;+ // The host may have dismissed the picker (Esc / backdrop / X) while the read+ // + POST were in flight and moved on to a different record. Selecting now+ // would write this image onto whatever the host has open instead — so the+ // upload stays in the gallery, but nothing is picked.+ if (sessionRef.current !== session) return;onSelect?.(normalizeImage({ filename: saved.filename, path: saved.path }));onClose?.();};diff --git a/client/src/components/imageGen/GalleryImagePicker.test.jsx b/client/src/components/imageGen/GalleryImagePicker.test.jsxindex 0ab7b4c2b3..604fed028c 100644--- a/client/src/components/imageGen/GalleryImagePicker.test.jsx+++ b/client/src/components/imageGen/GalleryImagePicker.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { render, screen, fireEvent, waitFor } from '@testing-library/react';+import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';import GalleryImagePicker from './GalleryImagePicker';import toast from '../ui/Toast';@@ -162,6 +162,25 @@ describe('GalleryImagePicker', () => {expect(onSelect).not.toHaveBeenCalled();});+ // Hosts are master-detail editors: dismissing the modal mid-upload and picking+ // a different album/artist/author must not write this image onto that record.+ it('drops an upload that lands after the picker was dismissed', async () => {+ let settleUpload;+ uploadGalleryImage.mockReturnValue(new Promise((resolve) => { settleUpload = resolve; }));+ const onSelect = vi.fn();+ const onClose = vi.fn();+ const { rerender } = render(<GalleryImagePicker open allowUpload onSelect={onSelect} onClose={onClose} />);+ await pickFile(new File(['x'], 'photo.png', { type: 'image/png' }));+ await waitFor(() => expect(uploadGalleryImage).toHaveBeenCalledTimes(1));++ // Host dismissed the modal (Esc / backdrop / X) while the POST was in flight.+ rerender(<GalleryImagePicker open={false} allowUpload onSelect={onSelect} onClose={onClose} />);+ await act(async () => { settleUpload({ filename: 'late.png', path: '/data/images/late.png' }); });++ expect(onSelect).not.toHaveBeenCalled();+ expect(onClose).not.toHaveBeenCalled();+ });+it('allows a large file when no host cap narrows the wire limit', async () => {uploadGalleryImage.mockResolvedValue({ filename: 'big.png', path: '/data/images/big.png' });render(<GalleryImagePicker open allowUpload onSelect={vi.fn()} onClose={vi.fn()} />);diff --git a/client/src/components/music/AlbumsManager.jsx b/client/src/components/music/AlbumsManager.jsxindex ed31fc4527..a8c678b634 100644--- a/client/src/components/music/AlbumsManager.jsx+++ b/client/src/components/music/AlbumsManager.jsx@@ -166,8 +166,9 @@ export default function AlbumsManager() {// Both "pick an existing gallery image" and "upload one from disk" land here —// GalleryImagePicker's `allowUpload` owns the read + POST and hands back the- // saved image already normalized (issue #4127). No album-switch guard needed:- // this fires synchronously from the modal, which sits over the album list.+ // saved image already normalized (issue #4127). The album-switch guard that+ // used to live here moved into the picker, which drops an upload that lands+ // after its modal was dismissed.const handleCoverPick = (item) => {setGalleryOpen(false);const url = item?.previewUrl || (item?.filename ? `/data/images/${item.filename}` : '');