Skip to content

Commit 7811093

Browse files
authored
Fix null renderMarkdown and add tests (#2724)
1 parent 7d67f26 commit 7811093

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7979
- Fixes [#2709](https://github.com/microsoft/BotFramework-WebChat/issues/2709). Reduce wasted render of activities by memoizing partial result of `<BasicTranscript>`, by [@compulim](https://github.com/compulim) in PR [#2710](https://github.com/microsoft/BotFramework-WebChat/pull/2710)
8080
- Fixes [#2710](https://github.com/microsoft/BotFramework-WebChat/issues/2710). Suggested actions container should persist for AT, by [@corinagum](https://github.com/corinagum) in PR [#2710](https://github.com/microsoft/BotFramework-WebChat/pull/2710)
8181
- Fixes [#2718](https://github.com/microsoft/BotFramework-WebChat/issues/2718). Add `Object.is` polyfill for IE11, by [@compulim](https://github.com/compulim) in PR [#2719](https://github.com/microsoft/BotFramework-WebChat/pull/2719)
82+
- Fixes [#2723](https://github.com/microsoft/BotFramework-WebChat/issues/2723). Fix `renderMarkdown` should not be called if it is `undefined` in minimal bundle, by [@compulim](https://github.com/compulim) in PR [#2724](https://github.com/microsoft/BotFramework-WebChat/pull/2724)
8283

8384
### Changed
8485

20.5 KB
Loading

__tests__/hooks/useRenderMarkdownAsHTML.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ test('renderMarkdown should use custom Markdown transform function from props',
2424
pageObjects.runHook('useRenderMarkdownAsHTML', [], fn => fn('Hello, World!'))
2525
).resolves.toMatchInlineSnapshot(`"HELLO, WORLD!"`);
2626
});
27+
28+
test('renderMarkdown should return falsy if the custom Markdown transform function is null', async () => {
29+
const { pageObjects } = await setupWebDriver({
30+
props: {
31+
renderMarkdown: null
32+
}
33+
});
34+
35+
await expect(pageObjects.runHook('useRenderMarkdownAsHTML', [], fn => !!fn)).resolves.toMatchInlineSnapshot(`false`);
36+
});

__tests__/markdown.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ test('hero card', async () => {
2222

2323
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
2424
});
25+
26+
test('null renderMarkdown function', async () => {
27+
const { driver, pageObjects } = await setupWebDriver({ props: { renderMarkdown: null } });
28+
29+
await pageObjects.sendMessageViaSendBox('echo **This text should be plain text**', { waitForSend: true });
30+
31+
await driver.wait(allImagesLoaded(), timeouts.fetch);
32+
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
33+
34+
const base64PNG = await driver.takeScreenshot();
35+
36+
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
37+
});

packages/bundle/src/useComposerProps.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default function useComposerProps({ attachmentMiddleware, renderMarkdown,
2222
return {
2323
attachmentMiddleware: patchedAttachmentMiddleware,
2424
extraStyleSet,
25-
renderMarkdown: renderMarkdown || (text => defaultRenderMarkdown(text, patchedStyleOptions))
25+
renderMarkdown:
26+
typeof renderMarkdown === 'undefined' ? text => defaultRenderMarkdown(text, patchedStyleOptions) : renderMarkdown
2627
};
2728
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback } from 'react';
1+
import { useMemo } from 'react';
22

33
import useStyleOptions from '../hooks/useStyleOptions';
44
import useWebChatUIContext from './internal/useWebChatUIContext';
@@ -7,5 +7,8 @@ export default function useRenderMarkdownAsHTML() {
77
const { renderMarkdown } = useWebChatUIContext();
88
const [styleOptions] = useStyleOptions();
99

10-
return useCallback(markdown => renderMarkdown(markdown, styleOptions), [renderMarkdown, styleOptions]);
10+
return useMemo(() => renderMarkdown && (markdown => renderMarkdown(markdown, styleOptions)), [
11+
renderMarkdown,
12+
styleOptions
13+
]);
1114
}

0 commit comments

Comments
 (0)