From 7dcaa0af73e51418b6a84beb5f5053e0e0a49e0b Mon Sep 17 00:00:00 2001 From: Peter Innes Date: Wed, 22 Apr 2026 10:26:58 -0700 Subject: [PATCH 1/2] Addressing bug in SendFailed.tsx which results in undefined reference error with prevActivityKeysOfSendFailed. --- .../src/Transcript/LiveRegion/SendFailed.tsx | 12 ++++++++---- packages/component/src/hooks/internal/usePrevious.ts | 10 ++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/component/src/Transcript/LiveRegion/SendFailed.tsx b/packages/component/src/Transcript/LiveRegion/SendFailed.tsx index 3af37838ad..e822560917 100644 --- a/packages/component/src/Transcript/LiveRegion/SendFailed.tsx +++ b/packages/component/src/Transcript/LiveRegion/SendFailed.tsx @@ -1,10 +1,10 @@ -import { hooks } from 'botframework-webchat-api'; import { memo, useMemo } from 'react'; -import usePrevious from '../../hooks/internal/usePrevious'; -import { useLiveRegion } from '../../providers/LiveRegionTwin'; import { SEND_FAILED } from '../../types/internal/SendStatus'; +import { hooks } from 'botframework-webchat-api'; import isPresentational from './isPresentational'; +import { useLiveRegion } from '../../providers/LiveRegionTwin'; +import usePrevious from '../../hooks/internal/usePrevious'; const { useGetActivityByKey, useLocalizer, useSendStatusByActivityKey } = hooks; @@ -44,7 +44,7 @@ const LiveRegionSendFailed = () => { /** Returns localized "Failed to send message." */ const liveRegionSendFailedAlt = localize('TRANSCRIPT_LIVE_REGION_SEND_FAILED_ALT'); - const prevActivityKeysOfSendFailed = usePrevious(activityKeysOfSendFailed); + const prevActivityKeysOfSendFailed = usePrevious(activityKeysOfSendFailed, new Set()); /** True, if one or more non-presentational activities start appears as "send failed", otherwise, false. */ const hasNewSendFailed = useMemo(() => { @@ -52,6 +52,10 @@ const LiveRegionSendFailed = () => { return false; } + if (!prevActivityKeysOfSendFailed) { + return true; + } + for (const key of activityKeysOfSendFailed.keys()) { if (!prevActivityKeysOfSendFailed.has(key)) { return true; diff --git a/packages/component/src/hooks/internal/usePrevious.ts b/packages/component/src/hooks/internal/usePrevious.ts index 0f02fcd7e7..81c4cc93c4 100644 --- a/packages/component/src/hooks/internal/usePrevious.ts +++ b/packages/component/src/hooks/internal/usePrevious.ts @@ -1,12 +1,14 @@ -// TODO: [P0] #4133 Don't copy. import { useEffect, useRef } from 'react'; -export default function usePrevious(value: T): T { - const ref = useRef(); +export default function usePrevious(value: T): T | undefined; +export default function usePrevious(value: T, initialValue: T): T; + +export default function usePrevious(value: T, initialValue?: T | undefined): T | undefined { + const ref = useRef(initialValue); useEffect(() => { ref.current = value; }); return ref.current; -} +} \ No newline at end of file From 764dccfbd881e82b1e9fb77df38209c00c21b16c Mon Sep 17 00:00:00 2001 From: Peter Innes <53846082+peterinnesmsft@users.noreply.github.com> Date: Wed, 22 Apr 2026 19:10:23 +0000 Subject: [PATCH 2/2] Add new line at EOF for usePrevious. --- packages/component/src/hooks/internal/usePrevious.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/component/src/hooks/internal/usePrevious.ts b/packages/component/src/hooks/internal/usePrevious.ts index 81c4cc93c4..c49f55bfb5 100644 --- a/packages/component/src/hooks/internal/usePrevious.ts +++ b/packages/component/src/hooks/internal/usePrevious.ts @@ -11,4 +11,4 @@ export default function usePrevious(value: T, initialValue?: T | undefined): }); return ref.current; -} \ No newline at end of file +}