diff --git a/__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-chromium-darwin.png b/__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-chromium-darwin.png
new file mode 100644
index 000000000..d91956789
Binary files /dev/null and b/__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-chromium-darwin.png differ
diff --git a/__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-firefox-darwin.png b/__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-firefox-darwin.png
new file mode 100644
index 000000000..58a4c9785
Binary files /dev/null and b/__visual_tests__/__snapshots__/workflow-tests.spec.ts/104-firefox-darwin.png differ
diff --git a/__visual_tests__/const.ts b/__visual_tests__/const.ts
index b8cbde4f5..5ebc1074e 100644
--- a/__visual_tests__/const.ts
+++ b/__visual_tests__/const.ts
@@ -15,4 +15,5 @@ export const WidgetComponentIds = {
INPUT: '.sendbird-input__input',
CHIPS_CONTAINER: '.sendbird-form-chip__container',
FORM: '#aichatbot-widget-form',
+ MARKDOWN: '.widget-markdown',
};
diff --git a/__visual_tests__/workflow-tests.spec.ts b/__visual_tests__/workflow-tests.spec.ts
index 49778c090..e2926b483 100644
--- a/__visual_tests__/workflow-tests.spec.ts
+++ b/__visual_tests__/workflow-tests.spec.ts
@@ -137,3 +137,20 @@ test('103', async ({ page, browserName }) => {
await page.waitForTimeout(2000);
await assertScreenshot(page, '103-6', browserName);
});
+
+/**
+ * 104
+ * Workflow - Markdown response
+ * Steps:
+ * 1. Send the trigger message: "give me a markdown message"
+ */
+test('104', async ({ page, browserName }) => {
+ await loadWidget(page);
+ // 1
+ await sendTextMessage(page, 'give me a markdown message', 2000);
+
+ // Check if the fallback component is visible
+ const fallback = page.locator(WidgetComponentIds.MARKDOWN);
+ await fallback.waitFor({ state: 'visible' });
+ await assertScreenshot(page, '104', browserName);
+});
diff --git a/src/components/TokensBody.tsx b/src/components/TokensBody.tsx
index 059d68e37..fe5c63aa8 100644
--- a/src/components/TokensBody.tsx
+++ b/src/components/TokensBody.tsx
@@ -1,5 +1,5 @@
import DOMPurify from 'dompurify';
-import Markdown from 'markdown-to-jsx';
+import { lazy, Suspense } from 'react';
import styled from 'styled-components';
import BotMessageBottom from './BotMessageBottom';
@@ -10,6 +10,8 @@ import { Token, TokenType } from '../utils';
import './markdown.scss';
+const Markdown = lazy(() => import('markdown-to-jsx'));
+
type TokensBodyProps = {
tokens: Token[];
sources?: Source[];
@@ -44,66 +46,74 @@ export default function TokensBody({ tokens, sources }: TokensBodyProps) {
const { enableSourceMessage } = useConstantState();
return (
-
- {children}
-
- ),
+
- {children}
-
- ),
+ overrides: {
+ // Note that this is to remove text-align: right by the library.
+ td: {
+ component: ({ children, ...props }) => (
+
+ {children}
+
+ ),
+ },
+ // Note that this is to remove text-align: right by the library.
+ th: {
+ component: ({ children, ...props }) => (
+
+ {children}
+
+ ),
+ },
+ a: {
+ component: ({ children, ...props }) => (
+
+ {children}
+
+ ),
+ },
},
- a: {
- component: ({ children, ...props }) => (
-
- {children}
-
- ),
- },
- },
- }}
- >
- {token.value}
-