Skip to content

Commit f9321ff

Browse files
committed
fix(Chat): ui.Chat() should never scroll a parent element of the chat container element
1 parent 82a83ee commit f9321ff

File tree

6 files changed

+95
-48
lines changed

6 files changed

+95
-48
lines changed

js/chat/chat.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,13 @@ class ChatContainer extends LightElement {
528528

529529
// ------- Register custom elements and shiny bindings ---------
530530

531-
customElements.define(CHAT_MESSAGE_TAG, ChatMessage);
532-
customElements.define(CHAT_USER_MESSAGE_TAG, ChatUserMessage);
533-
customElements.define(CHAT_MESSAGES_TAG, ChatMessages);
534-
customElements.define(CHAT_INPUT_TAG, ChatInput);
535-
customElements.define(CHAT_CONTAINER_TAG, ChatContainer);
531+
if (!customElements.get(CHAT_MESSAGES_TAG)) {
532+
customElements.define(CHAT_MESSAGE_TAG, ChatMessage);
533+
customElements.define(CHAT_USER_MESSAGE_TAG, ChatUserMessage);
534+
customElements.define(CHAT_MESSAGES_TAG, ChatMessages);
535+
customElements.define(CHAT_INPUT_TAG, ChatInput);
536+
customElements.define(CHAT_CONTAINER_TAG, ChatContainer);
537+
}
536538

537539
window.Shiny.addCustomMessageHandler(
538540
"shinyChatMessage",
@@ -561,3 +563,5 @@ window.Shiny.addCustomMessageHandler(
561563
el.dispatchEvent(evt);
562564
}
563565
);
566+
567+
export { CHAT_CONTAINER_TAG };

js/markdown-stream/markdown-stream.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import ClipboardJS from "clipboard";
66
import hljs from "highlight.js/lib/common";
77
import { Renderer, parse } from "marked";
88

9+
import { CHAT_CONTAINER_TAG } from "../chat/chat";
10+
911
import {
1012
LightElement,
1113
createElement,
@@ -282,6 +284,11 @@ class MarkdownElement extends LightElement {
282284
while (el) {
283285
if (el.scrollHeight > el.clientHeight) return el;
284286
el = el.parentElement;
287+
if (el?.tagName === CHAT_CONTAINER_TAG) {
288+
// Stop searching for scrollable parents if we reach <shiny-chat-container>.
289+
// If the chat is scrollable, a scrollable element would've been found already.
290+
break;
291+
}
285292
}
286293
return null;
287294
}

shiny/www/py-shiny/chat/chat.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/chat/chat.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/markdown-stream/markdown-stream.js

Lines changed: 66 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/markdown-stream/markdown-stream.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)