Skip to content

Commit f3ee0df

Browse files
committed
fix: prevent initial send failed live region crash
1 parent 1431fe4 commit f3ee0df

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Legends:
2323

2424
- Added `styleOptions.richCardTitleOmitHeadingRole` (default `false`) to opt out of `style: 'heading'` on rich card titles, in PR [#5839](https://github.com/microsoft/BotFramework-WebChat/pull/5839), by [@cjennison](https://github.com/cjennison)
2525

26+
### Fixed
27+
28+
- Fixed an error when a failed activity is present when Web Chat mounts, resolving [#5812](https://github.com/microsoft/BotFramework-WebChat/issues/5812), by [@OEvgeny](https://github.com/OEvgeny)
29+
2630

2731
## [4.19.1] - 2026-06-09
2832

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/** @jest-environment @happy-dom/jest-environment */
2+
3+
import React from 'react';
4+
import { render } from 'react-dom';
5+
import { act } from 'react-dom/test-utils';
6+
7+
import { hooks } from 'botframework-webchat-api';
8+
9+
import LiveRegionSendFailed from './SendFailed';
10+
import { useLiveRegion } from '../../providers/LiveRegionTwin';
11+
12+
jest.mock('botframework-webchat-api', () => ({
13+
hooks: {
14+
useGetActivityByKey: jest.fn(),
15+
useLocalizer: jest.fn(),
16+
useSendStatusByActivityKey: jest.fn()
17+
}
18+
}));
19+
jest.mock('../../providers/LiveRegionTwin', () => ({ useLiveRegion: jest.fn() }));
20+
21+
const mockUseGetActivityByKey = hooks.useGetActivityByKey as jest.Mock;
22+
const mockUseLiveRegion = useLiveRegion as jest.Mock;
23+
const mockUseLocalizer = hooks.useLocalizer as jest.Mock;
24+
const mockUseSendStatusByActivityKey = hooks.useSendStatusByActivityKey as jest.Mock;
25+
26+
describe('LiveRegionSendFailed', () => {
27+
let container: HTMLDivElement;
28+
29+
beforeEach(() => {
30+
container = document.createElement('div');
31+
32+
mockUseGetActivityByKey.mockReturnValue(() => ({ channelData: {}, text: 'Hello, World!', type: 'message' }));
33+
mockUseLocalizer.mockReturnValue(() => 'Failed to send message.');
34+
mockUseSendStatusByActivityKey.mockReturnValue([new Map([['activity', 'send failed']])]);
35+
});
36+
37+
afterEach(() => {
38+
container.remove();
39+
jest.clearAllMocks();
40+
});
41+
42+
test('renders when the initial send status is failed', () => {
43+
act(() => {
44+
render(<LiveRegionSendFailed />, container);
45+
});
46+
47+
expect(mockUseLiveRegion.mock.calls[0][0]()).toBe(false);
48+
});
49+
});

packages/component/src/Transcript/LiveRegion/SendFailed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const LiveRegionSendFailed = () => {
4848

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

0 commit comments

Comments
 (0)