Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/component/src/Transcript/LiveRegion/SendFailed.tsx
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -44,14 +44,18 @@ 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<string>());

/** True, if one or more non-presentational activities start appears as "send failed", otherwise, false. */
const hasNewSendFailed = useMemo<boolean>(() => {
if (activityKeysOfSendFailed === prevActivityKeysOfSendFailed) {
return false;
}

if (!prevActivityKeysOfSendFailed) {
return true;
}

Comment on lines +55 to +58
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevActivityKeysOfSendFailed is always a Set<string> here because usePrevious is called with an initialValue. The if (!prevActivityKeysOfSendFailed) { return true; } branch is therefore dead code and (if it ever became reachable) would incorrectly return true even when activityKeysOfSendFailed is empty. Suggest removing this check entirely, or (if you intend to support an undefined previous value) change it to return activityKeysOfSendFailed.size > 0 instead of unconditionally true.

Suggested change
if (!prevActivityKeysOfSendFailed) {
return true;
}

Copilot uses AI. Check for mistakes.
for (const key of activityKeysOfSendFailed.keys()) {
if (!prevActivityKeysOfSendFailed.has(key)) {
return true;
Expand Down
10 changes: 6 additions & 4 deletions packages/component/src/hooks/internal/usePrevious.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// TODO: [P0] #4133 Don't copy.
import { useEffect, useRef } from 'react';

export default function usePrevious<T>(value: T): T {
const ref = useRef<T>();
export default function usePrevious<T>(value: T): T | undefined;
export default function usePrevious<T>(value: T, initialValue: T): T;

export default function usePrevious<T>(value: T, initialValue?: T | undefined): T | undefined {
const ref = useRef<T | undefined>(initialValue);

useEffect(() => {
ref.current = value;
});

return ref.current;
}
}

Check failure on line 14 in packages/component/src/hooks/internal/usePrevious.ts

View workflow job for this annotation

GitHub Actions / Static code analysis

Insert `⏎`
Loading