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

settle a composite board's render job once per job, not once per render

[._.]/ Adam Eivy6865a7c11244
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 54cfda2916..5a1872d7a4 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -74,4 +74,4 @@
- **The "Pick from Gallery" picker could only be narrowed by typing, so finding one object in one universe meant recalling a word from its prompt.** It now carries two dropdowns beside the search box: a scope select that groups every universe and media collection under `<optgroup>`s, and a type select built from the `entryCategory`/`entryKind` tags the Universe Builder stamps onto sidecars, labelled through the same `humanizeCategory` the Builder uses. Those two are separate vocabularies — a user-authored bucket can legitimately be keyed `canon` — so the type options are prefixed by which field they filter and grouped under Categories/Entry kinds rather than flattened into one list where the bucket and the stage would silently match each other. All three filters AND-combine, and both dropdowns list only universes/collections/types that actually match an image currently in the picker — a scope that can only ever produce an empty grid isn't offered, and a selection that stops matching resets itself to "All" rather than silently blanking the grid. Collection membership is matched on the stored `{ kind, ref }` pair (the same `<kind>:<ref>` string `normalizeImage` puts on `item.key`), not on a bare filename, so a collection holding video refs alongside images filters correctly. Both option fetches are best-effort: if the collections or universes call fails the picker keeps working, falling back to the universe name stamped on each sidecar, and the fetched lists are dropped on close so a reopen can't filter fresh images against stale membership. Sidecars are unvalidated JSON that also arrive from peers, so a tag that isn't a usable string is skipped rather than crashing the render — which surfaced a latent bug in the shared `humanizeCategory`: its label lookup wasn't `hasOwn`-guarded, so a user-authored category keyed `constructor` or `toString` resolved to an inherited function and handed every caller a label that throws on the next string method (#3479).
-- **Composite boards were the only Universe Builder surface with no thumbnail, so a rendered board looked unrendered.** Characters, places, objects and category variations all show their latest render as an `EntryThumbSlot` avatar with a click-to-preview lightbox; the Composites tab showed label + prompt only. Nothing was missing server-side — `compile.js` already stamps an `entryRef` of kind `sheet` on each queued board render and the completion hook already appends the resulting filename to that board's `imageRefs[]`, so the data was sitting in the record with nothing reading it. Composite rows now render through the same `EntryCard` shell + three-state `EntryThumbSlot` the variation and canon rows use (in-flight spinner → rendered thumbnail → empty placeholder with a one-click render button), so their spacing and locked accent can no longer drift from the other surfaces, and clicking a board opens the same page-level lightbox with the real render prompt hydrated from the gallery sidecar. `useRenderJobQueue` had been dropping `sheet`-kind jobs on the grounds that no row consumed them; with every kind the server stamps now settled by a row, the filter is deleted rather than widened — an allowlist that already covers everything can only ever fail closed on the next kind added, silently, with no spinner and no error. Two things this collapsed rather than copied: the row settles through `EntryThumbSlot`'s existing `onComplete` bridge instead of opening a second `useMediaJobProgress` subscription against a jobId the slot is already watching (which is what the variation and canon rows do, at the cost of a row re-render per diffusion tick), and the append-dedupe-cap that had been inlined at four client call sites is now `appendImageRefById` in `lib/bibleLimits.js`, the client mirror of the server's `mapAppendImageRef`.
+- **Composite boards were the only Universe Builder surface with no thumbnail, so a rendered board looked unrendered.** Characters, places, objects and category variations all show their latest render as an `EntryThumbSlot` avatar with a click-to-preview lightbox; the Composites tab showed label + prompt only. Nothing was missing server-side — `compile.js` already stamps an `entryRef` of kind `sheet` on each queued board render and the completion hook already appends the resulting filename to that board's `imageRefs[]`, so the data was sitting in the record with nothing reading it. Composite rows now render through the same `EntryCard` shell + three-state `EntryThumbSlot` the variation and canon rows use (in-flight spinner → rendered thumbnail → empty placeholder with a one-click render button), so their spacing and locked accent can no longer drift from the other surfaces, and clicking a board opens the same page-level lightbox with the real render prompt hydrated from the gallery sidecar. `useRenderJobQueue` had been dropping `sheet`-kind jobs on the grounds that no row consumed them; with every kind the server stamps now settled by a row, the filter is deleted rather than widened — an allowlist that already covers everything can only ever fail closed on the next kind added, silently, with no spinner and no error. Two things this collapsed rather than copied: the row settles through `EntryThumbSlot`'s existing `onComplete` bridge instead of opening a second `useMediaJobProgress` subscription against a jobId the slot is already watching (which is what the variation and canon rows do, at the cost of a row re-render per diffusion tick), and the two page-level job handlers that had each inlined the same append-dedupe-cap now share `appendImageRefById` in `lib/bibleLimits.js`, the client mirror of the server's `mapAppendImageRef` (three other surfaces still inline their own copy). The settle callback is memoized rather than rebuilt per render: `MediaJobThumb` fires its completion effect on `[filename, onFilename]`, so a fresh arrow would re-settle the same job on every keystroke in the builder draft, each one a full gallery refetch — there is a test that fails against the unstable form.
diff --git a/client/src/components/universeBuilder/CompositeSheetsEditor.jsx b/client/src/components/universeBuilder/CompositeSheetsEditor.jsx
index 22fc3e5a79..0aa77bd8ac 100644
--- a/client/src/components/universeBuilder/CompositeSheetsEditor.jsx
+++ b/client/src/components/universeBuilder/CompositeSheetsEditor.jsx
@@ -1,4 +1,4 @@
-import { useState } from 'react';
+import { useCallback, useState } from 'react';
import { Plus, Play, Lock, Unlock, Edit3, X } from 'lucide-react';
import { COMPOSITE_PROMPT_MAX } from '../../services/api';
import { COMPOSITE_BOARD_KINDS, compositeKindLabel } from '../../lib/universeBuilderShared';
@@ -239,14 +239,24 @@ function SheetRow({
onToggleLock, onStartEdit, onRemove,
}) {
const renders = Array.isArray(sheet.imageRefs) ? sheet.imageRefs : [];
- // Three-state thumbnail (pending spinner / rendered image / empty placeholder
- // with a one-click render button), matching the variation + canon rows so a
- // rendered board reads the same way its characters / places / objects do.
// `onComplete` is EntryThumbSlot's own settle bridge — it fires with the
// rendered filename, or with `null` on a terminal failure/cancel — so the row
// needs no second `useMediaJobProgress` subscription against a jobId the slot
- // is already watching. `inFlightJobId` comes back from the closure because the
+ // is already watching. `inFlightJobId` rides in from the closure because the
// parent shifts exactly that jobId out of the board's pending queue.
+ //
+ // The identity MUST be stable: MediaJobThumb fires its `onFilename` effect on
+ // `[effectiveFilename, onFilename]`, so a fresh arrow per render would settle
+ // the same job again on every page re-render (every keystroke in the builder
+ // draft) — each one a full listImageGallery() refetch — instead of once when
+ // the job lands.
+ const handleSettled = useCallback(
+ (filename) => onJobSettled?.(sheet.id, filename, inFlightJobId),
+ [onJobSettled, sheet.id, inFlightJobId],
+ );
+ // Three-state thumbnail (pending spinner / rendered image / empty placeholder
+ // with a one-click render button), matching the variation + canon rows so a
+ // rendered board reads the same way its characters / places / objects do.
const thumbnail = (
<EntryThumbSlot
inFlightJobId={inFlightJobId}
@@ -255,7 +265,7 @@ function SheetRow({
canRender={canRender}
onRender={onRender}
onPreview={onPreview}
- onComplete={onJobSettled ? (filename) => onJobSettled(sheet.id, filename, inFlightJobId) : null}
+ onComplete={handleSettled}
/>
);
const title = (
diff --git a/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx b/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx
index d90969059f..7aaf9cd286 100644
--- a/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx
+++ b/client/src/components/universeBuilder/CompositeSheetsEditor.test.jsx
@@ -95,6 +95,26 @@ describe('CompositeSheetsEditor', () => {
await waitFor(() => expect(onJobSettled).toHaveBeenCalledWith('sheet-1', 'fresh.png', 'job-9'));
});
+ // MediaJobThumb fires its onFilename effect on [effectiveFilename, onFilename],
+ // so an unstable callback identity would re-settle the same job on every parent
+ // re-render — each one a full gallery refetch. Re-rendering with untouched props
+ // must not produce a second settle.
+ it('settles a completed job once, not once per parent re-render', async () => {
+ job = { status: 'completed', filename: 'fresh.png', error: null };
+ const onJobSettled = vi.fn();
+ const props = {
+ sheets: [sheet({ id: 'sheet-1' })],
+ onChange: () => {},
+ pendingByEntryId: { 'sheet-1': 'job-9' },
+ onJobSettled,
+ };
+ const { rerender } = render(<CompositeSheetsEditor {...props} />);
+ await waitFor(() => expect(onJobSettled).toHaveBeenCalled());
+ rerender(<CompositeSheetsEditor {...props} />);
+ rerender(<CompositeSheetsEditor {...props} />);
+ expect(onJobSettled).toHaveBeenCalledTimes(1);
+ });
+
it('settles with a null filename on a terminal failure so the parent still clears the pending entry', async () => {
job = { status: 'failed', filename: null, error: 'boom' };
const onJobSettled = vi.fn();