Skip to content

Commit 960e671

Browse files
authored
Fix rendering erroneous Adaptive Card (#4852)
* Fix rendering erroneous Adaptive Card * Update PR number
1 parent 7953dff commit 960e671

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4646
- Fixes [#4718](https://github.com/microsoft/BotFramework-WebChat/issues/4718). In high contrast mode, Adaptive Card buttons, when pushed, should highlighted properly, by [@compulim](https://github.com/compulim), in PR [#4746](https://github.com/microsoft/BotFramework-WebChat/pull/4746)
4747
- Fixes [#4721](https://github.com/microsoft/BotFramework-WebChat/issues/4721) and [#4726](https://github.com/microsoft/BotFramework-WebChat/issues/4726). Adaptive Cards `TextBlock` heading elements should start at level 2, by [@compulim](https://github.com/compulim), in PR [#4747](https://github.com/microsoft/BotFramework-WebChat/issues/4747)
4848
- Fixes [#3699](https://github.com/microsoft/BotFramework-WebChat/issues/3699). Correcting timestamp roundoff, by [@compulim](https://github.com/compulim), in PR [#4821](https://github.com/microsoft/BotFramework-WebChat/pull/4821)
49+
- Fixes [#4849](https://github.com/microsoft/BotFramework-WebChat/issues/4849). Rendering an erroneous Adaptive Cards should bail out and not throw `MutationObserver` error, by [@compulim](https://github.com/compulim), in PR [#4852](https://github.com/microsoft/BotFramework-WebChat/issues/4852)
4950

5051
## [4.15.8] - 2023-06-06
5152

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
8+
</head>
9+
<body>
10+
<main id="webchat"></main>
11+
<script>
12+
run(async function () {
13+
const { directLine, store } = testHelpers.createDirectLineEmulator();
14+
15+
WebChat.renderWebChat(
16+
{
17+
directLine,
18+
store
19+
},
20+
document.getElementById('webchat')
21+
);
22+
23+
await pageConditions.uiConnected();
24+
await directLine.emulateIncomingActivity({
25+
attachments: [
26+
{
27+
contentType: 'application/vnd.microsoft.card.adaptive',
28+
content: {
29+
// We want to render a failing Adaptive Cards, adding "*" here to fail the renderer.
30+
type: '*AdaptiveCard*',
31+
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
32+
version: '1.5',
33+
body: [
34+
{
35+
text: 'Hello, World!',
36+
type: 'TextBlock'
37+
}
38+
]
39+
}
40+
}
41+
],
42+
type: 'message'
43+
});
44+
});
45+
</script>
46+
</body>
47+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */
2+
3+
describe('Adaptive Cards', () => {
4+
test('should not error when render an erroneous card', () => runHTML('adaptiveCards.renderError.html'));
5+
});

packages/bundle/src/adaptiveCards/Attachment/AdaptiveCardRenderer.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,14 @@ const AdaptiveCardRenderer: VFC<AdaptiveCardRendererProps> = ({
222222
// Apply all mods regardless whether the element changed or not.
223223
// This is because we have undoed mods when we call the `useXXXModEffect` hook.
224224
useLayoutEffect(() => {
225-
applyActionShouldBePushButtonMod(element, actionPerformedClassName);
226-
applyActionSetShouldNotBeMenuBarMod(element);
227-
applyActiveElementMod(element);
228-
applyDisabledMod(element, disabled);
229-
applyPersistValuesMod(element);
230-
applyRoleMod(element);
225+
if (element) {
226+
applyActionShouldBePushButtonMod(element, actionPerformedClassName);
227+
applyActionSetShouldNotBeMenuBarMod(element);
228+
applyActiveElementMod(element);
229+
applyDisabledMod(element, disabled);
230+
applyPersistValuesMod(element);
231+
applyRoleMod(element);
232+
}
231233
}, [
232234
actionPerformedClassName,
233235
applyActionShouldBePushButtonMod,
@@ -240,6 +242,8 @@ const AdaptiveCardRenderer: VFC<AdaptiveCardRendererProps> = ({
240242
element
241243
]);
242244

245+
errors?.length && console.warn('botframework-webchat: Failed to render Adaptive Cards.', errors);
246+
243247
return errors?.length ? (
244248
node_env === 'development' && <ErrorBox error={errors[0]} type={localize('ADAPTIVE_CARD_ERROR_BOX_TITLE_RENDER')} />
245249
) : (

0 commit comments

Comments
 (0)