Draft
Conversation
Custom Hook (useChatState) * Pure state management: All chat state logic centralized * Typed methods: appendMessage, appendMessageChunk, clearMessages, etc. * No DOM dependencies: Can be tested independently Clean Component Architecture * ChatInput: Uses callback pattern to expose methods (onMethodsReady) * ChatContainer: Uses custom hook + listens for CustomEvents * No imperative refs: All communication through props and events Shiny Integration Ready * Event-driven: Components listen for shiny-chat-* CustomEvents * Type-safe: All event details properly typed * Simple wrapper: Future Shiny component just dispatches events
cpsievert
commented
Sep 30, 2025
Comment on lines
+10
to
+15
| // Message operations (for Shiny integration) | ||
| appendMessage: (message: Message) => void | ||
| appendMessageChunk: (message: Message) => void | ||
| clearMessages: () => void | ||
| removeLoadingMessage: () => void | ||
| updateUserInput: (update: UpdateUserInput) => void |
Collaborator
Author
There was a problem hiding this comment.
Seems like we could take some inspiration from #105 and re-work/simplify the event system?
cpsievert
commented
Sep 30, 2025
Comment on lines
+132
to
+151
| handleWillContentChange = () => { | ||
| ShinyMarkdownStreamOutput.#doUnBind(this) | ||
| } | ||
|
|
||
| // Public callback methods for React component and testing | ||
| handleContentChange = () => { | ||
| // Render Shiny HTML dependencies and bind inputs/outputs | ||
| if (this.streaming) { | ||
| ShinyMarkdownStreamOutput._throttledBind(this) | ||
| } else { | ||
| ShinyMarkdownStreamOutput.#doBind(this) | ||
| } | ||
|
|
||
| // Callback for when content changes - can be used for custom logic | ||
| this.dispatchEvent( | ||
| new CustomEvent("contentchange", { | ||
| detail: { content: this.content }, | ||
| }), | ||
| ) | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
Feels like the binding logic could be moved into the MarkdownStream component implementation?
cpsievert
commented
Sep 30, 2025
| if (contentType === "text") { | ||
| return <div dangerouslySetInnerHTML={{ __html: processedContent }} /> | ||
| } else if (contentType === "html") { | ||
| return <div dangerouslySetInnerHTML={{ __html: processedContent }} /> |
Collaborator
Author
There was a problem hiding this comment.
This could do something closer to what 'react-markdown' does (parses string into hast tree, then creates a JSX runtime from that) https://github.com/remarkjs/react-markdown/blob/fda7fa560bec901a6103e195f9b1979dab543b17/lib/index.js#L348
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.