Skip to content

Commit a682747

Browse files
committed
Be slightly less agressive about updating scrollable element. Remove unnecessary console.error()
1 parent f030b93 commit a682747

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

js/chat/chat.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ $(function () {
360360
const el = document.getElementById(message.id);
361361

362362
if (!el) {
363-
const errMsg = `
364-
Unable to handle Chat() message since element with id ${message.id} wasn't
365-
found. Do you need to call .ui() (Express) or need a
363+
showShinyClientMessage({
364+
status: "error",
365+
message: `Unable to handle Chat() message since element with id
366+
${message.id} wasn't found. Do you need to call .ui() (Express) or need a
366367
chat_ui('${message.id}') in the UI (Core)?
367-
`;
368-
console.error(errMsg);
369-
showShinyClientMessage({ message: errMsg, status: "error" });
368+
`,
369+
});
370370
return;
371371
}
372372

js/markdown-stream/markdown-stream.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ class MarkdownElement extends LightElement {
8787

8888
protected willUpdate(changedProperties: PropertyValues): void {
8989
if (changedProperties.has("content")) {
90-
this.#updateScrollableElement();
9190
this.#isContentBeingAdded = true;
91+
// A scrollable element might not be available until the content
92+
// grows to a certain size. So, keep looking for it until it's found.
93+
if (!this.#scrollableElement) this.#updateScrollableElement();
94+
}
95+
if (changedProperties.has("streaming")) {
96+
this.#updateScrollableElement();
9297
}
9398
}
9499

@@ -201,6 +206,8 @@ class MarkdownElement extends LightElement {
201206

202207
#cleanup(): void {
203208
this.#scrollableElement?.removeEventListener("scroll", this.#onScroll);
209+
this.#scrollableElement = null;
210+
this.#isUserScrolled = false;
204211
}
205212
}
206213

@@ -213,13 +220,12 @@ function handleMessage(message: ContentMessage | IsStreamingMessage): void {
213220
const el = document.getElementById(message.id) as MarkdownElement;
214221

215222
if (!el) {
216-
const errMsg = `
217-
Unable to handle MarkdownStream() message since element with id ${message.id}
218-
wasn't found. Do you need to call .ui() (Express) or need a
219-
output_markdown_stream('${message.id}') in the UI (Core)?
220-
`;
221-
console.error(errMsg);
222-
showShinyClientMessage({ message: errMsg, status: "error" });
223+
showShinyClientMessage({
224+
status: "error",
225+
message: `Unable to handle MarkdownStream() message since element with id
226+
${message.id} wasn't found. Do you need to call .ui() (Express) or need a
227+
output_markdown_stream('${message.id}') in the UI (Core)?`,
228+
});
223229
return;
224230
}
225231

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

Lines changed: 3 additions & 4 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: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)