Skip to content

Commit 53e881d

Browse files
committed
Don't render deleted messages, handle null render promises
1 parent 514a21b commit 53e881d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/jupyter-chat/src/components/messages/messages.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ export function ChatMessages(props: BaseMessageProps): JSX.Element {
115115
const observer = new IntersectionObserver(entries => {
116116
// Used on first rendering, to ensure all the message as been rendered once.
117117
if (!allRendered) {
118-
Promise.all(renderedPromise.current.map(p => p.promise)).then(() => {
118+
const activePromises = renderedPromise.current
119+
// Filter out nulls signigying deleted messages
120+
.filter(p => p)
121+
.map(p => p.promise);
122+
123+
Promise.all(activePromises).then(() => {
119124
setAllRendered(true);
120125
});
121126
}
@@ -181,6 +186,11 @@ export function ChatMessages(props: BaseMessageProps): JSX.Element {
181186
)}
182187
<Box ref={refMsgBox} className={clsx(MESSAGES_BOX_CLASS)}>
183188
{messages.map((message, i) => {
189+
// Skip rendering deleted messages while preventing sparse array
190+
if (message.deleted) {
191+
listRef.current[i] = null;
192+
return null;
193+
}
184194
renderedPromise.current[i] = new PromiseDelegate();
185195
return (
186196
// extra div needed to ensure each bubble is on a new line

0 commit comments

Comments
 (0)