From 489d99dbc6c19722fe2782fef347df576208d086 Mon Sep 17 00:00:00 2001 From: hba <87194281+hubzhooba@users.noreply.github.com> Date: Wed, 2 Jul 2025 16:55:40 +0800 Subject: [PATCH 1/2] Cap dry run history at 5 and add defensive handling for corrupted storage --- src/app/entity/[slug]/ProcessInteraction.tsx | 10 +++------- src/components/RequestHistoryPanel.tsx | 14 +++++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/app/entity/[slug]/ProcessInteraction.tsx b/src/app/entity/[slug]/ProcessInteraction.tsx index a5e4b12..5cfbf7d 100644 --- a/src/app/entity/[slug]/ProcessInteraction.tsx +++ b/src/app/entity/[slug]/ProcessInteraction.tsx @@ -14,7 +14,7 @@ import { MonoFontFF } from "@/components/RootLayout/fonts" import { prettifyResult } from "@/utils/ao-utils" import { truncateId } from "@/utils/data-utils" -import { RequestHistoryPanel, dryRunHistoryStore } from "@/components/RequestHistoryPanel" +import { RequestHistoryPanel, dryRunHistoryStore, addToDryRunHistory } from "@/components/RequestHistoryPanel" type ProcessInteractionProps = { processId: string @@ -58,9 +58,7 @@ export function ProcessInteraction(props: ProcessInteractionProps) { timestamp: new Date().toISOString(), } - const existing = dryRunHistoryStore.get() || [] - const updated = [...existing, newItem].slice(-10) - dryRunHistoryStore.set(updated) + addToDryRunHistory(newItem) } else { const sentMsgId = await message({ ...msg, @@ -78,9 +76,7 @@ export function ProcessInteraction(props: ProcessInteractionProps) { sentMessageId: sentMsgId, } - const existing = dryRunHistoryStore.get() || [] - const updated = [...existing.slice(-9), newItem] - dryRunHistoryStore.set(updated) + addToDryRunHistory(newItem) } setResponse(JSON.stringify(prettifyResult(json), null, 2)) diff --git a/src/components/RequestHistoryPanel.tsx b/src/components/RequestHistoryPanel.tsx index bd34543..8e6f4d1 100644 --- a/src/components/RequestHistoryPanel.tsx +++ b/src/components/RequestHistoryPanel.tsx @@ -20,6 +20,17 @@ export const dryRunHistoryStore = persistentAtom( { encode: JSON.stringify, decode: JSON.parse }, ) +const MAX_HISTORY = 5; + +export function addToDryRunHistory(newItem: any) { + const prev = dryRunHistoryStore.get() || []; + const updated = [...prev, newItem]; + if (updated.length > MAX_HISTORY) { + updated.splice(0, updated.length - MAX_HISTORY); // Remove oldest + } + dryRunHistoryStore.set(updated); +} + const ChevronDownIcon = () => ( import("./CodeEditor").then(m=>({default:m.CodeEdi export function RequestHistoryPanel({ onSelect }: RequestHistoryPanelProps) { const address = useActiveAddress() - const history = useStore(dryRunHistoryStore) + const rawHistory = useStore(dryRunHistoryStore) + const history = Array.isArray(rawHistory) ? rawHistory : [] const [expanded, setExpanded] = useState(false) const [hoveredId, setHoveredId] = useState(null) From f28e414aa43fbdda121aedd362f6a330c6878e9d Mon Sep 17 00:00:00 2001 From: hba <87194281+hubzhooba@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:16:31 +0800 Subject: [PATCH 2/2] virtualize && data.length > pageSize * 100 --- src/components/AsyncTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AsyncTable.tsx b/src/components/AsyncTable.tsx index afdec9f..37126ad 100644 --- a/src/components/AsyncTable.tsx +++ b/src/components/AsyncTable.tsx @@ -180,7 +180,7 @@ export function AsyncTable(props: AsyncTableProps) { - {virtualize && data.length > pageSize * 3 ? ( + {virtualize && data.length > pageSize * 100 ? (