Skip to content
Closed
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
4 changes: 2 additions & 2 deletions js/dist/shinychat.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/dist/shinychat.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions js/src/chat/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ export function chatReducer(state: ChatState, action: AnyAction): ChatState {
? last.content + action.content
: action.content

// Update contentType if the chunk provides one (e.g., transition
// from "markdown" to "html" when UI elements appear mid-stream)
const contentType = action.content_type ?? last.contentType

return { ...state, streamingMessage: { ...last, content, contentType } }
// Do not update contentType mid-stream: switching processors between
// chunks causes HAST structural changes that unmount/remount HTML islands
// (e.g. <shinychat-raw-html>). The markdownProcessor already handles raw
// HTML via rehypeRaw, so the chunk_start contentType is sufficient.
return { ...state, streamingMessage: { ...last, content } }
}

case "chunk_end": {
Expand Down
8 changes: 5 additions & 3 deletions js/src/markdown/MarkdownContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { RawHTML } from "../chat/RawHTML"
const baseAssistantComponents: Record<string, ComponentType<unknown>> = {
pre: CopyableCodeBlock as ComponentType<unknown>,
table: BootstrapTable as ComponentType<unknown>,
"shinychat-raw-html": (({ node }: { node?: Element }) => (
<RawHTML html={node ? toHtml(node.children) : ""} displayContents />
)) as ComponentType<unknown>,
"shinychat-raw-html": (({ node }: { node?: Element }) => {
const html = node ? toHtml(node.children) : ""
return <RawHTML html={html} displayContents />
}) as ComponentType<unknown>,
}

const baseUserComponents: Record<string, ComponentType<unknown>> = {
Expand Down Expand Up @@ -48,6 +49,7 @@ export function MarkdownContent({
: isUser
? userMarkdownProcessor
: markdownProcessor

const resolvedTagToComponentMap = useMemo(
() =>
isUser
Expand Down
2 changes: 1 addition & 1 deletion js/src/markdown/processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export const markdownProcessor = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeHighlight, { detect: false, ignoreMissing: true })
.use(rehypeRaw)
.use(rehypeLazyContinuation)
.use(rehypeUnwrapBlockCEs)
.use(rehypeUncontrolledInputs)
.use(rehypeAccessibleSuggestions)
.use(rehypeExternalLinks)
.use(rehypeHighlight, { detect: false, ignoreMissing: true })
.freeze()

/**
Expand Down
4 changes: 2 additions & 2 deletions js/tests/chat/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe("chatReducer", () => {
expect(next.messages).toBe(state.messages)
})

it("updates contentType when chunk provides one", () => {
it("ignores contentType provided by a chunk (locked to chunk_start)", () => {
const msg = makeAssistantMsg({
streaming: true,
contentType: "markdown",
Expand All @@ -203,7 +203,7 @@ describe("chatReducer", () => {
operation: "append",
content_type: "html",
})
expect(next.streamingMessage!.contentType).toBe("html")
expect(next.streamingMessage!.contentType).toBe("markdown")
})

it("keeps contentType when chunk does not provide one", () => {
Expand Down
2 changes: 1 addition & 1 deletion pkg-py/src/shinychat/www/GIT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c21dd47a2b512aa40c4ac37455ea4e71db1eeedc
bbbb76dcd6598cbfafdc830efb72c9bc4ba5b06d
4 changes: 2 additions & 2 deletions pkg-py/src/shinychat/www/shinychat.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg-py/src/shinychat/www/shinychat.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg-r/inst/lib/shiny/GIT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c21dd47a2b512aa40c4ac37455ea4e71db1eeedc
bbbb76dcd6598cbfafdc830efb72c9bc4ba5b06d
4 changes: 2 additions & 2 deletions pkg-r/inst/lib/shiny/shinychat.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg-r/inst/lib/shiny/shinychat.js.map

Large diffs are not rendered by default.

Loading