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

address review (claude): request missing gallery posters one at a time

[._.]/ Adam Eivycbafa2207b76
diff --git a/client/src/components/codeAnimation/CodeAnimationGallery.jsx b/client/src/components/codeAnimation/CodeAnimationGallery.jsx
index 29cb593d6c..16adcf1921 100644
--- a/client/src/components/codeAnimation/CodeAnimationGallery.jsx
+++ b/client/src/components/codeAnimation/CodeAnimationGallery.jsx
@@ -75,11 +75,14 @@ export default function CodeAnimationGallery() {
}, [refreshFirst]);
// A completed job with no poster (one from before posters existed, or whose
- // capture was interrupted) gets one request per visit; the server draws them
- // one at a time. The mount guard is lifetime-scoped on purpose: this effect
- // re-runs on every items change, which must not drop an in-flight answer.
+ // capture was interrupted) gets one request per visit. Requests go one at a
+ // time: each is held open while the server draws, and a burst would occupy
+ // every browser connection to this origin. The mount guard is lifetime-scoped
+ // on purpose: this effect re-runs on every items change, which must not drop
+ // an in-flight answer.
const mounted = useMounted();
const requested = useRef(new Set());
+ const queue = useRef(Promise.resolve());
const [capturing, setCapturing] = useState(() => new Set());
useEffect(() => {
const missing = items.filter((item) => item.status === 'completed' && !item.posterVersion && !requested.current.has(item.id));
@@ -87,14 +90,17 @@ export default function CodeAnimationGallery() {
setCapturing((previous) => new Set([...previous, ...missing.map((item) => item.id)]));
for (const { id } of missing) {
requested.current.add(id);
- requestCodeAnimationPoster(id, { silent: true })
- .then(({ posterVersion }) => posterVersion)
- .catch(() => null)
- .then((posterVersion) => {
- if (!mounted.current) return;
- setCapturing((previous) => { const next = new Set(previous); next.delete(id); return next; });
- if (posterVersion) setItems((previous) => previous.map((entry) => (entry.id === id ? { ...entry, posterVersion } : entry)));
- });
+ queue.current = queue.current.then(() => {
+ if (!mounted.current) return null;
+ return requestCodeAnimationPoster(id, { silent: true })
+ .then(({ posterVersion }) => posterVersion)
+ .catch(() => null)
+ .then((posterVersion) => {
+ if (!mounted.current) return;
+ setCapturing((previous) => { const next = new Set(previous); next.delete(id); return next; });
+ if (posterVersion) setItems((previous) => previous.map((entry) => (entry.id === id ? { ...entry, posterVersion } : entry)));
+ });
+ });
}
}, [items, setItems, mounted]);
diff --git a/client/src/pages/CodeAnimation.test.jsx b/client/src/pages/CodeAnimation.test.jsx
index 207e9af0b6..11a9c4e366 100644
--- a/client/src/pages/CodeAnimation.test.jsx
+++ b/client/src/pages/CodeAnimation.test.jsx
@@ -272,26 +272,30 @@ describe('Code Animation page', () => {
expect(listCodeAnimationJobPage).toHaveBeenCalledTimes(1);
});
- it('shows saved posters, draws a missing one once, and labels unfinished jobs', async () => {
+ it('shows saved posters, draws missing ones once each and one at a time, and labels unfinished jobs', async () => {
listCodeAnimationJobPage.mockResolvedValue({ items: [
{ id: 'job-a', status: 'completed', title: 'With poster', posterVersion: 11, createdAt: '2026-01-03T00:00:00.000Z' },
{ id: 'job-b', status: 'completed', title: 'Needs poster', createdAt: '2026-01-02T00:00:00.000Z' },
+ { id: 'job-d', status: 'completed', title: 'Also needs poster', createdAt: '2026-01-02T00:00:00.000Z' },
{ id: 'job-c', status: 'running', title: 'Still going', createdAt: '2026-01-01T00:00:00.000Z' },
- ], total: 3, counts: { running: 1, completed: 2 }, nextCursor: null });
- let drawPoster;
- requestCodeAnimationPoster.mockImplementation(() => new Promise((resolve) => { drawPoster = resolve; }));
+ ], total: 4, counts: { running: 1, completed: 3 }, nextCursor: null });
+ const draws = [];
+ requestCodeAnimationPoster.mockImplementation(() => new Promise((resolve) => { draws.push(resolve); }));
const { container } = await renderPage('/code-animation/gallery');
await waitFor(() => expect(screen.getByRole('link', { name: /With poster/ })).toHaveAttribute('href', '/code-animation/job-a'));
expect(container.querySelector('img[src="/posters/job-a.jpg?v=11"]')).not.toBeNull();
- expect(screen.getByText('Drawing thumbnail…')).toBeInTheDocument();
+ expect(screen.getAllByText('Drawing thumbnail…')).toHaveLength(2);
expect(screen.getAllByText('In progress').length).toBeGreaterThan(0);
- expect(requestCodeAnimationPoster).toHaveBeenCalledTimes(1);
+ await waitFor(() => expect(requestCodeAnimationPoster).toHaveBeenCalledTimes(1));
expect(requestCodeAnimationPoster).toHaveBeenCalledWith('job-b', { silent: true });
- await act(async () => drawPoster({ posterVersion: 22 }));
+ await act(async () => draws[0]({ posterVersion: 22 }));
expect(container.querySelector('img[src="/posters/job-b.jpg?v=22"]')).not.toBeNull();
+ await waitFor(() => expect(requestCodeAnimationPoster).toHaveBeenCalledTimes(2));
+ expect(requestCodeAnimationPoster).toHaveBeenLastCalledWith('job-d', { silent: true });
+ await act(async () => draws[1]({ posterVersion: null }));
expect(screen.queryByText('Drawing thumbnail…')).not.toBeInTheDocument();
await emitSocket('code-animation:changed', { id: 'job-c' });
- expect(requestCodeAnimationPoster).toHaveBeenCalledTimes(1);
+ expect(requestCodeAnimationPoster).toHaveBeenCalledTimes(2);
});
it('loads one compact page, stays idle, and refreshes on durable changes and reconnect', async () => {