From 442669499a90414c08ec4bc350830c81e81e750d Mon Sep 17 00:00:00 2001 From: Saurav Sharma Date: Fri, 13 Mar 2026 16:24:44 +0530 Subject: [PATCH 1/2] fix(actions): fix state mutation and slice direction in ActionLogger The addAction callback was mutating objects in place (previous.count++ and action.count = 1), violating React's immutability principle. Additionally, slice(0, limit) was retaining the oldest actions and discarding newest ones. Changed to slice(-limit) to keep the most recent entries, which is the expected behavior for an action log. Fixes #34052 --- .../src/actions/containers/ActionLogger/index.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/core/src/actions/containers/ActionLogger/index.tsx b/code/core/src/actions/containers/ActionLogger/index.tsx index b56398b11b24..8a786144175f 100644 --- a/code/core/src/actions/containers/ActionLogger/index.tsx +++ b/code/core/src/actions/containers/ActionLogger/index.tsx @@ -36,15 +36,16 @@ export default function ActionLogger({ active, api }: ActionLoggerProps) { const addAction = useCallback((action: ActionDisplay) => { setActions((prevActions) => { - const newActions = [...prevActions]; - const previous = newActions.length && newActions[newActions.length - 1]; + const previous = prevActions.length ? prevActions[prevActions.length - 1] : null; + if (previous && safeDeepEqual(previous.data, action.data)) { - previous.count++; + const updated = [...prevActions]; + updated[updated.length - 1] = { ...previous, count: previous.count + 1 }; + return updated.slice(-action.options.limit); } else { - action.count = 1; - newActions.push(action); + const newAction = { ...action, count: 1 }; + return [...prevActions, newAction].slice(-action.options.limit); } - return newActions.slice(0, action.options.limit); }); }, []); From b0d193cff48f5eaa3b507bceb0f8debbce3759f5 Mon Sep 17 00:00:00 2001 From: Saurav Sharma Date: Fri, 13 Mar 2026 16:39:39 +0530 Subject: [PATCH 2/2] fix(actions): guard against non-positive limit values Sanitize action.options.limit to handle zero, negative, or undefined values. When limit is non-positive, return all actions without slicing. Addresses CodeRabbit review feedback. --- code/core/src/actions/containers/ActionLogger/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/core/src/actions/containers/ActionLogger/index.tsx b/code/core/src/actions/containers/ActionLogger/index.tsx index 8a786144175f..eee512710baa 100644 --- a/code/core/src/actions/containers/ActionLogger/index.tsx +++ b/code/core/src/actions/containers/ActionLogger/index.tsx @@ -36,15 +36,17 @@ export default function ActionLogger({ active, api }: ActionLoggerProps) { const addAction = useCallback((action: ActionDisplay) => { setActions((prevActions) => { + const limit = Math.max(0, Number(action.options?.limit) || 0); const previous = prevActions.length ? prevActions[prevActions.length - 1] : null; if (previous && safeDeepEqual(previous.data, action.data)) { const updated = [...prevActions]; updated[updated.length - 1] = { ...previous, count: previous.count + 1 }; - return updated.slice(-action.options.limit); + return limit > 0 ? updated.slice(-limit) : updated; } else { const newAction = { ...action, count: 1 }; - return [...prevActions, newAction].slice(-action.options.limit); + const newActions = [...prevActions, newAction]; + return limit > 0 ? newActions.slice(-limit) : newActions; } }); }, []);