perf(site): fix compiler memoization gap in AgentDetailInput (#23683)

The React Compiler failed to memoize the messages derivation
chain because a useDashboard() hook call sat between the
messages computation and its consumer (getLatestContextUsage).
An IIFE around the context usage logic also fragmented the
dependency chain.

Replacing the IIFE with a ternary and reordering the non-hook
computation before the hook call lets the compiler group
messages + getLatestContextUsage into a single cache guard
keyed on messagesByID and orderedMessageIDs.
This commit is contained in:
Mathias Fredriksson
2026-03-26 20:30:06 +02:00
committed by GitHub
parent 6cbb7c6da7
commit 94e5de22f7
@@ -174,15 +174,12 @@ export const AgentDetailInput: FC<AgentDetailInputProps> = ({
const messages = orderedMessageIDs
.map((messageID) => messagesByID.get(messageID))
.filter(isChatMessage);
const rawUsage = getLatestContextUsage(messages);
const latestContextUsage = rawUsage
? { ...rawUsage, compressionThreshold }
: rawUsage;
const { organizations } = useDashboard();
const organizationId = organizations[0]?.id;
const latestContextUsage = (() => {
const usage = getLatestContextUsage(messages);
if (!usage) {
return usage;
}
return { ...usage, compressionThreshold };
})();
const {
attachments,
textContents,