Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fix missing session when trying to display an error duing bookmarking. (#1984)

* Fixed an issue with `ui.Chat()` sometimes wanting to scroll a parent element. (#1996)


## [1.4.0] - 2025-04-08

Expand Down
20 changes: 15 additions & 5 deletions js/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,19 @@ class ChatContainer extends LightElement {

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

customElements.define(CHAT_MESSAGE_TAG, ChatMessage);
customElements.define(CHAT_USER_MESSAGE_TAG, ChatUserMessage);
customElements.define(CHAT_MESSAGES_TAG, ChatMessages);
customElements.define(CHAT_INPUT_TAG, ChatInput);
customElements.define(CHAT_CONTAINER_TAG, ChatContainer);
const chatCustomElements = [
{ tag: CHAT_MESSAGE_TAG, component: ChatMessage },
{ tag: CHAT_USER_MESSAGE_TAG, component: ChatUserMessage },
{ tag: CHAT_MESSAGES_TAG, component: ChatMessages },
{ tag: CHAT_INPUT_TAG, component: ChatInput },
{ tag: CHAT_CONTAINER_TAG, component: ChatContainer }
];

chatCustomElements.forEach(({ tag, component }) => {
if (!customElements.get(tag)) {
customElements.define(tag, component);
}
});

window.Shiny.addCustomMessageHandler(
"shinyChatMessage",
Expand Down Expand Up @@ -590,3 +598,5 @@ window.Shiny.addCustomMessageHandler(
el.dispatchEvent(evt);
}
);

export { CHAT_CONTAINER_TAG };
8 changes: 8 additions & 0 deletions js/markdown-stream/markdown-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import ClipboardJS from "clipboard";
import hljs from "highlight.js/lib/common";
import { Renderer, parse } from "marked";

import { CHAT_CONTAINER_TAG } from "../chat/chat";

import {
LightElement,
createElement,
Expand Down Expand Up @@ -282,6 +284,12 @@ class MarkdownElement extends LightElement {
while (el) {
if (el.scrollHeight > el.clientHeight) return el;
el = el.parentElement;
if (el?.tagName === CHAT_CONTAINER_TAG) {
// This ensures that we do not accidentally scroll a parent element of the chat
// container. If the chat container itself is scrollable, a scrollable element
// would already have been identified.
break;
}
}
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions shiny/www/py-shiny/chat/chat.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions shiny/www/py-shiny/chat/chat.js.map

Large diffs are not rendered by default.

96 changes: 66 additions & 30 deletions shiny/www/py-shiny/markdown-stream/markdown-stream.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions shiny/www/py-shiny/markdown-stream/markdown-stream.js.map

Large diffs are not rendered by default.

Loading