feat: search the server from the Asset Picker without shrinking preview's catalog

The Picker asked for `{ managementStatus: "READY", limit: 50 }` and
ignored `nextCursor`, so the 51st-oldest READY asset onward could not be
inserted at all. It sits inside the editing flow, where scrolling a long
list is the wrong interaction, so it gets search rather than a "더 보기"
control -- and it still loads a first page, because an empty panel until
you type is hostile to an author reaching for the asset they uploaded a
minute ago.

The trap this creates is the substance of the change. The editor screen's
Asset array feeds two consumers with opposite needs: the Picker's
*displayed* list, which a search must narrow, and Instant Preview's
*resolution catalog*, which a search must never narrow -- its gate
rejects any key no loaded asset backs. Handing search results straight to
the screen's `setAssets` would blank previously-inserted evidence figures
the moment the author typed a query.

They are kept apart by making the screen's callback additive by
construction rather than by convention: `mergeAssetCatalog` (domain,
beside `findResolvableAsset`) can only grow the set, and both writers --
observed pages and fresh uploads -- go through it. The prop is renamed
`onAssetsObserved` so the contract reads as "what the Picker saw", not
"what to show"; the replacing version was one `setAssets` reference away
and looked correct.

A key backed by neither the first page nor the current results is still
unresolvable. That is the known deferred limitation, not this change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-08-18 13:16:31 +09:00
co-authored by Claude Opus 5
parent a5825c18b5
commit f69edb633d
7 changed files with 428 additions and 33 deletions
@@ -63,6 +63,40 @@ function outranks(candidate: ResolvableAsset, incumbent: ResolvableAsset): boole
return candidate.id > incumbent.id;
}
/**
* Grows the set of Assets an evidence key can resolve against, never shrinks
* it.
*
* Alignment follow-up, item 2. The editor screen's Asset array feeds two
* consumers whose needs are opposite: the Picker's *displayed* list, which a
* search must narrow, and Instant Preview's *resolution catalog*, which a
* search must never narrow -- `instantPreviewEvidenceKeyGate` rejects any key
* no loaded Asset backs, so an Asset dropped from the array turns a directive
* that rendered a moment ago into an error panel. Handing the Picker's search
* results straight to `setAssets` would do exactly that: type a query that
* excludes an already-inserted figure and the live preview blanks, purely
* because the author touched a search box.
*
* Making the screen's callback *additive* is what keeps the two apart, and it
* has to be additive by construction rather than by convention -- the
* replacing version was one `setAssets` reference away and read as correct.
* `incoming` is placed first and `current` deduped behind it, so a re-fetched
* Asset's fresher fields win while every previously observed Asset survives;
* that is also exactly the expression a single freshly uploaded Asset needs,
* so both callers share one rule.
*
* Order is not load-bearing for resolution -- `findResolvableAsset` is
* explicitly order-independent -- so this only has to be total and stable.
*/
export function mergeAssetCatalog(
current: readonly Asset[],
incoming: readonly Asset[],
): readonly Asset[] {
if (incoming.length === 0) return current;
const arriving = new Set(incoming.map((asset) => asset.id));
return [...incoming, ...current.filter((asset) => !arriving.has(asset.id))];
}
/**
* The evidence-key gate every caller uses. A key is referenceable when a real
* Asset resolves it, or when it is the caller's own legacy static key -- the