Skip to content

Commit deb5cf4

Browse files
author
David Scheier
committed
split first chunk on line breaks so that a long output with markdown is already rendered while animated
1 parent d1551b2 commit deb5cf4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/webchat/store/messages/message-reducer.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const createMessageReducer = (getState: () => { config: ConfigState }) =>
6060
return [...state, newMessage];
6161
}
6262

63-
// If message doesn't have text, still add an ID and animationState for enabling the animation
63+
// If message doesn't have text (e.g. Text with Quick Replies), still add an ID and animationState for enabling the animation.
6464
if (!newMessage.text) {
6565
return [...state, {
6666
...newMessage,
@@ -88,9 +88,12 @@ export const createMessageReducer = (getState: () => { config: ConfigState }) =>
8888

8989
// If no matching message, create new with array
9090
if (messageIndex === -1) {
91+
// break string into chunks on new lines so that markdown is evaluated while a long text is animated
92+
const textChunks = (newMessage.text as string).split(/(\n)/).filter(chunk => chunk.length > 0);
93+
9194
return [...state, {
9295
...newMessage,
93-
text: [newMessage.text as string],
96+
text: textChunks,
9497
id: newMessageId,
9598
animationState: "start",
9699
}];

0 commit comments

Comments
 (0)