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
address review (codex r4): drop stale Load more page when filters change mid-flight (#1762)
[._.]/ Adam Eivy045f05e48664
diff --git a/client/src/pages/Catalog.jsx b/client/src/pages/Catalog.jsxindex 111b1610da..4b05f9c672 100644--- a/client/src/pages/Catalog.jsx+++ b/client/src/pages/Catalog.jsx@@ -14,7 +14,7 @@* universe/series.*/-import { useState, useEffect, useCallback, useMemo } from 'react';+import { useState, useEffect, useCallback, useMemo, useRef } from 'react';import { Link, useNavigate, useSearchParams } from 'react-router-dom';import { Sparkles, Plus, Search, FileInput, Loader2, RefreshCw, Wand2, X, LayoutGrid, Library, FolderPlus } from 'lucide-react';import toast from '../components/ui/Toast';@@ -208,10 +208,18 @@ export default function Catalog() {useEffect(() => loadStats(), [loadStats]);useEffect(() => loadFacets(), [loadFacets]);+ // Identity of the active filter set. loadMore captures it and drops its page+ // if the filters changed while the request was in flight — otherwise a stale+ // page would append into the freshly-reloaded (differently-filtered) list.+ const filterKey = `${selectedType}|${selectedTag}|${q}|${selectedUniverse}|${selectedSeries}`;+ const filterKeyRef = useRef(filterKey);+ filterKeyRef.current = filterKey;+const loadMore = () => {+ const key = filterKey;setLoadingMore(true);fetchListPage(items.length).then((list) => {- if (list) {+ if (key === filterKeyRef.current && list) {setItems((prev) => [...prev, ...list]);setHasMore(list.length === PAGE_SIZE);}diff --git a/client/src/pages/Catalog.test.jsx b/client/src/pages/Catalog.test.jsxindex b11dcc57d5..aa1a6e8b63 100644--- a/client/src/pages/Catalog.test.jsx+++ b/client/src/pages/Catalog.test.jsx@@ -345,6 +345,34 @@ describe('Catalog page', () => {await waitFor(() => expect(screen.getByText('Item 60')).toBeTruthy());});+ it('drops a stale Load more page when filters change mid-flight', async () => {+ const firstPage = Array.from({ length: 60 }, (_, i) => ({+ id: `pg-${i}`, name: `Page ${i}`, type: 'idea', payload: {}, tags: [],+ }));+ let resolveStale;+ const stalePromise = new Promise((r) => { resolveStale = r; });+ listCatalogIngredients.mockImplementation((params = {}) => {+ if (params.offset === 60 && !params.type) return stalePromise; // the in-flight loadMore+ if (params.type === 'character') {+ return Promise.resolve({ items: [{ id: 'flt', name: 'Filtered Only', type: 'character', payload: {}, tags: [] }], nextOffset: 1 });+ }+ return Promise.resolve({ items: firstPage, nextOffset: 60 }); // initial full page+ });+ renderCatalog();+ await waitFor(() => expect(screen.getByText('Page 0')).toBeTruthy());++ fireEvent.click(screen.getByRole('button', { name: /Load more/i })); // offset 60 → pending+ fireEvent.click(screen.getByRole('button', { name: /^Character/i })); // filter changes mid-flight+ await waitFor(() => expect(screen.getByText('Filtered Only')).toBeTruthy());++ await act(async () => {+ resolveStale({ items: [{ id: 'stale', name: 'Stale Page Item', type: 'idea', payload: {}, tags: [] }], nextOffset: 61 });+ });+ // The stale page must NOT leak into the now-character-filtered grid.+ expect(screen.queryByText('Stale Page Item')).toBeNull();+ expect(screen.getByText('Filtered Only')).toBeTruthy();+ });+it('switches to the Albums view and lazy-loads the Raw album', async () => {renderCatalog();await waitFor(() => expect(screen.getByText('Echo Saint')).toBeTruthy());