Skip to content

Bind the correct this context to chat's callback methods passed down to <markdown-stream> #1866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2025

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Feb 24, 2025

Follow up to #1845.

Note that, before this change, running the example below results in the following JS console warning:

markdown-stream.ts:122 Failed to call onContentUpdate callback: TypeError: Receiver must be an instance of class anonymous
from shiny.express import ui

welcome = """
<p>Here is the <span id="first" class='suggestion'>1st input suggestion</span>.
And here is a <span id="second" data-suggestion='The actual suggestion'>2nd suggestion</span>.
Finally, a <img id="third" data-suggestion='A 3rd, image-based, suggestion' src='shiny-hex.svg' height="50px" alt='Shiny logo'> image suggestion.</p>

<p>On the other hand, <span id="fourth" class="suggestion submit">this suggestion will auto-submit</span>.
And <span id="fifth" data-suggestion="another suggestion" data-suggestion-submit="true">this suggestion will also auto-submit</span>.</p>
"""

chat = ui.Chat(
    "chat",
    messages=[welcome],
)


chat.ui()


@chat.on_user_submit
async def on_user_submit(message: str):
    await chat.append_message(f"You said: {message}")

@cpsievert cpsievert requested a review from gadenbuie February 24, 2025 15:55
@cpsievert cpsievert added this to the Next Release milestone Feb 24, 2025
@cpsievert cpsievert force-pushed the fix/chat-content-change-handler branch from 58db719 to 2000fc9 Compare February 24, 2025 17:32
@cpsievert cpsievert merged commit c4500de into main Feb 24, 2025
41 checks passed
@cpsievert cpsievert deleted the fix/chat-content-change-handler branch February 24, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants