The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(gallery): the cap never drops sorted entries, and says when it drops any (D3b)
purple8d58ca7c4d46
diff --git a/src/components/create/experimental/CreatePanel.tsx b/src/components/create/experimental/CreatePanel.tsxindex 6fd89ece..bacca178 100644--- a/src/components/create/experimental/CreatePanel.tsx+++ b/src/components/create/experimental/CreatePanel.tsx@@ -10,6 +10,7 @@ import { isMlxImageHost } from '../../../api/mlx-image'import { downloadGalleryItem } from './galleryDownload'import { useComfyMedia } from './useComfyMedia'import { cn } from '../ui/cn'+import { HINWEIS_TEXT, HINWEIS_ZEILE } from '../../../lib/hinweis'import { itemsInFolder } from '../../../lib/gallery-folders'import { FolderFilter, MoveToFolderModal, OnBody } from './GalleryFolders'import { ContextMenu } from '../../ui/ContextMenu'@@ -37,6 +38,9 @@ export function CreatePanel({ open, onOpenChange, activeId, onSelect }: Props) {const all = useCreateStore((s) => s.gallery)const folderOpen = useCreateStore((s) => s.galleryFolderOpen)const removeFromGallery = useCreateStore((s) => s.removeFromGallery)+ // D3b: the cap took older unsorted entries; said once, until closed.+ const notice = useCreateStore((s) => s.galleryNotice)+ const dismissNotice = useCreateStore((s) => s.dismissGalleryNotice)// D3: the panel shows the open folder, "All" when none is open.const gallery = folderOpen === null ? all : itemsInFolder(all, folderOpen)const [moving, setMoving] = useState<string[]>([])@@ -167,6 +171,12 @@ export function CreatePanel({ open, onOpenChange, activeId, onSelect }: Props) {</div><FolderFilter />+ {notice && (+ <div role="status" className={cn(HINWEIS_ZEILE, 'items-center mx-3 mt-2 shrink-0')}>+ <p className={cn('flex-1', HINWEIS_TEXT.ruhig)}>{notice}</p>+ <BarBtn title="Dismiss" onClick={dismissNotice}><X size={13} /></BarBtn>+ </div>+ )}<OnBody><MoveToFolderModal ids={moving} onClose={() => setMoving([])} /></OnBody><OnBody><Modal open={confirming.length > 0} onClose={() => setConfirming([])} title="Delete from the gallery" maxWidth="max-w-md">diff --git a/src/components/create/experimental/__tests__/galerie-hinweis-d3b.test.tsx b/src/components/create/experimental/__tests__/galerie-hinweis-d3b.test.tsxnew file mode 100644index 00000000..1bf22460--- /dev/null+++ b/src/components/create/experimental/__tests__/galerie-hinweis-d3b.test.tsx@@ -0,0 +1,50 @@+// @vitest-environment jsdom+/**+ * D3b: when the cap took older unsorted entries, the gallery panel says so,+ * once, and the line can be closed. See stores/__tests__/galerie-speicher-d3b.test.ts.+ *+ * Run: npx vitest run src/components/create/experimental/__tests__/galerie-hinweis-d3b.test.tsx+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'++vi.mock('../CreateContext', () => ({+ useCreateExp: () => ({ quota: null, enhanceVideo: vi.fn() }),+}))+vi.mock('../useComfyMedia', () => ({+ useComfyMedia: () => ({ src: 'blob:media', onError: vi.fn(), onLoad: vi.fn() }),+}))+vi.mock('../../../../api/mlx-image', () => ({ isMlxImageHost: () => false, MLX_MODEL_PREFIX: 'MLX ' }))++import { useCreateStore, GALLERY_TRIMMED_NOTICE, type GalleryItem } from '../../../../stores/createStore'+import { CreatePanel } from '../CreatePanel'++const ITEM = (id: string): GalleryItem => ({+ id, type: 'image', filename: `${id}.png`, subfolder: '', prompt: `prompt ${id}`, negativePrompt: '',+ model: 'm.safetensors', modelType: 'sdxl', seed: 1, steps: 20, cfgScale: 5, sampler: 'euler',+ scheduler: 'normal', width: 512, height: 512, batchSize: 1, createdAt: 1,+})++beforeEach(() => {+ useCreateStore.setState({ backend: 'local', gallery: [ITEM('a')], galleryFolders: [], galleryFolderOpen: null, galleryNotice: null })+})+afterEach(() => { cleanup() })++const panel = () => render(<CreatePanel open onOpenChange={() => {}} activeId={null} onSelect={() => {}} />)++describe('the gallery panel', () => {+ it('shows nothing while no entry was dropped', () => {+ panel()+ expect(screen.queryByText(GALLERY_TRIMMED_NOTICE)).toBeNull()+ })++ it('says that older unsorted images were removed, and the line can be closed', () => {+ useCreateStore.setState({ galleryNotice: GALLERY_TRIMMED_NOTICE })+ panel()+ const line = screen.getByRole('status')+ expect(line.textContent).toContain(GALLERY_TRIMMED_NOTICE)+ fireEvent.click(screen.getByRole('button', { name: 'Dismiss' }))+ expect(screen.queryByText(GALLERY_TRIMMED_NOTICE)).toBeNull()+ expect(useCreateStore.getState().galleryNotice).toBeNull()+ })+})diff --git a/src/lib/fatal-error.ts b/src/lib/fatal-error.tsindex 6901cb7a..bb6edc57 100644--- a/src/lib/fatal-error.ts+++ b/src/lib/fatal-error.ts@@ -14,6 +14,8 @@* Deliberately EXCLUDES user DATA so a reset never destroys content:* chat-conversations (chats) · rag-store (knowledge) ·* locally-uncensored-memory (curated memory/brain).+ * create-store holds both: its settings go, its gallery and folders stay+ * (see resetSettingsAndReload).*/export const SETTINGS_STORAGE_KEYS = ['chat-settings',@@ -47,11 +49,38 @@ export function forceShowWindow(): void {} catch { /* ignore — best effort */ }}-/** Clear settings/state keys (keeps chats/knowledge/memory) and reload. */+/**+ * The part of the create-store that is the user's content, not a setting: the+ * gallery entries (prompts, settings of each render) and the folders sorted by+ * hand (D3b, Discord 01.11.2026). Null when the blob is not readable, then the+ * whole key goes as before, since a broken blob may be what took the app down.+ */+function createStoreContent(raw: string | null): string | null {+ if (!raw) return null+ try {+ const blob: unknown = JSON.parse(raw)+ const state = typeof blob === 'object' && blob !== null ? (blob as { state?: unknown }).state : null+ if (typeof state !== 'object' || state === null) return null+ const { gallery, galleryFolders } = state as { gallery?: unknown; galleryFolders?: unknown }+ if (!Array.isArray(gallery) && !Array.isArray(galleryFolders)) return null+ const kept: Record<string, unknown> = {}+ if (Array.isArray(gallery)) kept.gallery = gallery+ if (Array.isArray(galleryFolders)) kept.galleryFolders = galleryFolders+ return JSON.stringify({ state: kept, version: (blob as { version?: unknown }).version })+ } catch {+ return null+ }+}++/** Clear settings/state keys (keeps chats/knowledge/memory and the gallery) and reload. */export function resetSettingsAndReload(): void {try {for (const k of SETTINGS_STORAGE_KEYS) {- try { localStorage.removeItem(k) } catch { /* ignore one bad key */ }+ try {+ const content = k === 'create-store' ? createStoreContent(localStorage.getItem(k)) : null+ if (content) localStorage.setItem(k, content)+ else localStorage.removeItem(k)+ } catch { /* ignore one bad key */ }}} finally {window.location.reload()diff --git a/src/stores/__tests__/galerie-speicher-d3b.test.ts b/src/stores/__tests__/galerie-speicher-d3b.test.tsnew file mode 100644index 00000000..0ee48a4c--- /dev/null+++ b/src/stores/__tests__/galerie-speicher-d3b.test.ts@@ -0,0 +1,139 @@+// @vitest-environment jsdom+/**+ * D3b (Discord #bug-reports, 01.11.2026, 3.0.8): "all my gallery folders are+ * suddenly empty", twice, no trigger known. The image files were still in the+ * output folder; in LU the folder assignments and the prompts were gone.+ *+ * Cause: the gallery kept the newest 200 entries and dropped everything past+ * that without a word. A new result lands unsorted in front, so every render+ * pushed the oldest entry out, sorted or not; 200 new renders emptied every+ * folder. Now an entry in a folder is never dropped by the cap, the cap counts+ * unsorted entries only, and when some go the gallery says so, once per event.+ *+ * A second way to lose it: "Reset settings & reload" on the error screen+ * removed the whole create-store, gallery and folders with the settings.+ *+ * Run: npx vitest run src/stores/__tests__/galerie-speicher-d3b.test.ts+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { useCreateStore, GALLERY_TRIMMED_NOTICE, type GalleryItem } from '../createStore'+import { resetSettingsAndReload } from '../../lib/fatal-error'++const item = (n: number, extra: Partial<GalleryItem> = {}): GalleryItem => ({+ id: `g${n}`, type: 'image', filename: `ComfyUI_${n}.png`, subfolder: '', prompt: `prompt ${n} ${'p'.repeat(1500)}`,+ negativePrompt: '', model: 'm.safetensors', modelType: 'sdxl', seed: n, steps: 20, cfgScale: 5, sampler: 'euler',+ scheduler: 'normal', width: 1024, height: 1024, batchSize: 1, createdAt: n, ...extra,+})+const st = () => useCreateStore.getState()+const inFolder = () => st().gallery.filter((g) => g.folderId === 'f-1')+const unsorted = () => st().gallery.filter((g) => !g.folderId)++beforeEach(() => {+ localStorage.clear()+ useCreateStore.setState({+ backend: 'local',+ galleryFolders: [{ id: 'f-1', name: 'Sorted' }],+ galleryFolderOpen: null,+ // 200 sorted by hand, the oldest renders.+ gallery: Array.from({ length: 200 }, (_, i) => item(1000 - i, { folderId: 'f-1' })),+ galleryNotice: null,+ })+})+afterEach(() => { vi.restoreAllMocks() })++describe('the cap never takes a sorted entry', () => {+ it('200 sorted + 500 new: the folder stays complete, with its prompts', () => {+ for (let i = 0; i < 500; i++) st().addToGallery(item(5000 + i))+ expect(inFolder()).toHaveLength(200)+ expect(inFolder().every((g) => g.prompt.startsWith(`prompt ${g.seed} `))).toBe(true)+ // The cap still holds for unsorted ones: the newest 200.+ expect(unsorted()).toHaveLength(200)+ expect(unsorted()[0].id).toBe('g5499')+ expect(unsorted().some((g) => g.id === 'g5000')).toBe(false)+ // And it is what gets stored.+ const stored = JSON.parse(localStorage.getItem('create-store') ?? '{}').state.gallery as GalleryItem[]+ expect(stored.filter((g) => g.folderId === 'f-1')).toHaveLength(200)+ })++ it('results filed into the open folder are never dropped either', () => {+ useCreateStore.setState({ galleryFolderOpen: 'f-1' })+ for (let i = 0; i < 300; i++) st().addToGallery(item(5000 + i))+ expect(inFolder()).toHaveLength(500)+ expect(st().galleryNotice).toBeNull()+ })++ it('a cloud job list beyond the cap keeps the sorted entries too', () => {+ st().mergeGallery(Array.from({ length: 300 }, (_, i) => item(9000 + i, { id: `j${i}`, jobId: `j${i}` })))+ expect(inFolder()).toHaveLength(200)+ expect(unsorted()).toHaveLength(200)+ })+})++describe('when unsorted entries go, the gallery says so', () => {+ it('no word while nothing is dropped', () => {+ for (let i = 0; i < 200; i++) st().addToGallery(item(5000 + i))+ expect(st().galleryNotice).toBeNull()+ })++ it('one notice for the event, saying what happened', () => {+ for (let i = 0; i < 200; i++) st().addToGallery(item(5000 + i))+ const seen: (string | null)[] = []+ const off = useCreateStore.subscribe((s, prev) => { if (s.galleryNotice !== prev.galleryNotice) seen.push(s.galleryNotice) })+ st().mergeGallery(Array.from({ length: 50 }, (_, i) => item(9000 + i, { id: `j${i}`, jobId: `j${i}` })))+ off()+ expect(seen).toEqual([GALLERY_TRIMMED_NOTICE])+ expect(GALLERY_TRIMMED_NOTICE).toBe('Older unsorted images were removed from the gallery, the files are still in your output folder.')+ st().dismissGalleryNotice()+ expect(st().galleryNotice).toBeNull()+ })++ it('the notice is never stored', () => {+ for (let i = 0; i < 201; i++) st().addToGallery(item(5000 + i))+ expect(st().galleryNotice).toBe(GALLERY_TRIMMED_NOTICE)+ expect(JSON.parse(localStorage.getItem('create-store') ?? '{}').state).not.toHaveProperty('galleryNotice')+ })+})++describe('a full storage never replaces what is stored', () => {+ it('the last good blob stays when the write is refused', () => {+ st().addToGallery(item(5000))+ const good = localStorage.getItem('create-store')+ expect(good).toContain('"g5000"')+ vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {+ throw new DOMException('full', 'QuotaExceededError')+ })+ st().addToGallery(item(5001))+ vi.restoreAllMocks()+ expect(localStorage.getItem('create-store')).toBe(good)+ })+})++describe('"Reset settings & reload" keeps the gallery', () => {+ it('drops the settings of Create, keeps entries and folders', () => {+ localStorage.setItem('create-store', JSON.stringify({+ state: { steps: 99, sampler: 'broken', gallery: [item(1, { folderId: 'f-1' })], galleryFolders: [{ id: 'f-1', name: 'Sorted' }] },+ version: 2,+ }))+ localStorage.setItem('chat-settings', '{"state":{},"version":0}')+ const reload = vi.fn()+ vi.stubGlobal('location', { ...window.location, reload })+ resetSettingsAndReload()+ vi.unstubAllGlobals()+ expect(reload).toHaveBeenCalled()+ expect(localStorage.getItem('chat-settings')).toBeNull()+ const kept = JSON.parse(localStorage.getItem('create-store') ?? 'null')+ expect(kept.version).toBe(2)+ expect(kept.state.gallery.map((g: GalleryItem) => [g.id, g.folderId, g.prompt.slice(0, 8)])).toEqual([['g1', 'f-1', 'prompt 1']])+ expect(kept.state.galleryFolders).toEqual([{ id: 'f-1', name: 'Sorted' }])+ expect(kept.state).not.toHaveProperty('steps')+ expect(kept.state).not.toHaveProperty('sampler')+ })++ it('a create-store that is not readable is removed as before', () => {+ localStorage.setItem('create-store', '{broken')+ vi.stubGlobal('location', { ...window.location, reload: vi.fn() })+ resetSettingsAndReload()+ vi.unstubAllGlobals()+ expect(localStorage.getItem('create-store')).toBeNull()+ })+})diff --git a/src/stores/createStore.ts b/src/stores/createStore.tsindex cac607a0..b5f4f588 100644--- a/src/stores/createStore.ts+++ b/src/stores/createStore.ts@@ -34,6 +34,8 @@ const RUNTIME_ONLY_KEYS: readonly string[] = ['cloudImageCount',// The open gallery folder files new results, so it is never carried over.'galleryFolderOpen',+ // The line about trimmed entries belongs to the moment it happened.+ 'galleryNotice',// Review A kleiner Punkt 1 (studio-r2): the cloud video length selection,// own fields since this bugfix. Session-scratch like source/mask, not a// preference worth remembering across restarts.@@ -590,6 +592,8 @@ export interface CreateState {* lands in it, and a folder picked yesterday must not file today's renders* without the user seeing it. */galleryFolderOpen: string | null+ /** Said once when the cap took older unsorted entries (D3b). Runtime only. */+ galleryNotice: string | nullpromptHistory: string[]/** Runtime-only (not persisted): populated by useCreate.fetchModels so the* header-level CreateTopControls can render its model dropdown + Lichtschalter@@ -749,6 +753,7 @@ export interface CreateState {/** File entries under a folder, or under none with null. */moveToGalleryFolder: (ids: readonly string[], folderId: string | null) => voidsetGalleryFolderOpen: (id: string | null) => void+ dismissGalleryNotice: () => voidaddToPromptHistory: (prompt: string) => void/** Drop a single remembered prompt (the X next to the entry). */removeFromPromptHistory: (prompt: string) => void@@ -760,9 +765,32 @@ export interface CreateState {setMlxUpscale: (installed: boolean) => void}-/** The gallery keeps the newest N renders. */+/** The gallery keeps the newest N unsorted renders. */const GALLERY_CAP = 200+/** What the gallery says when the cap took entries (D3b). */+export const GALLERY_TRIMMED_NOTICE =+ 'Older unsorted images were removed from the gallery, the files are still in your output folder.'++/**+ * The cap, applied to `items` (newest first). D3b (Discord 01.11.2026): it+ * used to cut the whole list at 200, so new results pushed out the entries the+ * user had sorted into folders, prompts and all, without a word. An entry in a+ * folder is never dropped now; the cap counts unsorted entries only, the+ * oldest go first. The caller frees the dropped ones' media and says so.+ */+export function capGallery(items: readonly GalleryItem[]): { kept: GalleryItem[]; dropped: GalleryItem[] } {+ const kept: GalleryItem[] = []+ const dropped: GalleryItem[] = []+ let unsorted = 0+ for (const g of items) {+ if (g.folderId) kept.push(g)+ else if (unsorted < GALLERY_CAP) { kept.push(g); unsorted++ }+ else dropped.push(g)+ }+ return { kept, dropped }+}+/*** Hand a gallery item's in-memory media back to the renderer.*@@ -1183,6 +1211,7 @@ export const useCreateStore = create<CreateState>()(gallery: [],galleryFolders: [],galleryFolderOpen: null,+ galleryNotice: null,promptHistory: [],imageModelList: [],videoModelList: [],@@ -1726,17 +1755,17 @@ export const useCreateStore = create<CreateState>()(const filed = !item.folderId && s.galleryFolderOpen && s.galleryFolders.some((f) => f.id === s.galleryFolderOpen)? { ...item, folderId: s.galleryFolderOpen }: item- const next = [filed, ...s.gallery]// The cap used to drop the oldest renders silently, taking the only// reference to their blob: URLs with them — the bytes stayed pinned// for the rest of the session with nothing left to revoke them by.- for (const dropped of next.slice(GALLERY_CAP)) releaseItemMedia(dropped)- const gallery = next.slice(0, GALLERY_CAP)- if (s.backend !== 'cloud') return { gallery }+ const { kept: gallery, dropped } = capGallery([filed, ...s.gallery])+ for (const g of dropped) releaseItemMedia(g)+ const said = dropped.length > 0 ? { galleryNotice: GALLERY_TRIMMED_NOTICE } : {}+ if (s.backend !== 'cloud') return { gallery, ...said }const id = STUDIO_MODELS[item.model]?.sourceModel ?? item.model- if (cloudModelsFor('image').some((m) => m.id === id)) return withOwnStudioOptions(s, { gallery, cloudImageModel: id })- if (cloudModelsFor('video').some((m) => m.id === id)) return withOwnStudioOptions(s, { gallery, cloudVideoModel: id })- return { gallery }+ if (cloudModelsFor('image').some((m) => m.id === id)) return withOwnStudioOptions(s, { gallery, cloudImageModel: id, ...said })+ if (cloudModelsFor('video').some((m) => m.id === id)) return withOwnStudioOptions(s, { gallery, cloudVideoModel: id, ...said })+ return { gallery, ...said }}),updateGalleryItem: (id, patch) =>// NOT revoking a replaced dataUrl here on purpose: a patch lands while@@ -1776,8 +1805,9 @@ export const useCreateStore = create<CreateState>()(// blob-URL frei. Ein lokaler MLX-Clip, den eine Wolken-Hydrierung vom// Deckel schiebt, hielt seine Bytes sonst fuer den Rest der// Fenster-Lebensdauer fest (lu-desktop-oom-persist).- for (const dropped of merged.slice(GALLERY_CAP)) releaseItemMedia(dropped)- return { gallery: merged.slice(0, GALLERY_CAP) }+ const { kept, dropped } = capGallery(merged)+ for (const g of dropped) releaseItemMedia(g)+ return dropped.length > 0 ? { gallery: kept, galleryNotice: GALLERY_TRIMMED_NOTICE } : { gallery: kept }}),removeFromGallery: (id) => set((s) => {const gone = s.gallery.find((g) => g.id === id)@@ -1822,6 +1852,7 @@ export const useCreateStore = create<CreateState>()(gallery: s.gallery.map((g) => (pick.has(g.id) ? { ...g, folderId: folderId ?? undefined } : g)),}}),+ dismissGalleryNotice: () => set({ galleryNotice: null }),setGalleryFolderOpen: (id) => set((s) => ({galleryFolderOpen: id !== null && s.galleryFolders.some((f) => f.id === id) ? id : null,})),