Skip to content
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

Update Markdown elements even if invisible (e.g. inside tooltip or tab) #2803

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

me21
Copy link
Contributor

@me21 me21 commented Apr 2, 2024

This is an attempt to fix #2779. It seems to make Markdown elements update correctly but breaks Mermaid diagrams in Markdown elements, not sure why.
Additional changes are welcome.

@me21
Copy link
Contributor Author

me21 commented Apr 2, 2024

Mermaid diagrams work now.

@me21
Copy link
Contributor Author

me21 commented Apr 2, 2024

There is an annoying blinking during the update of the content if Mermaid diagram is shown. However, this bug is not so major, I think, and Markdown elements now are correctly shown in tooltips :)

@me21 me21 force-pushed the markdown-update-in-tooltip branch from aa0a213 to c73d85a Compare April 2, 2024 14:38
…ents to work inside tooltips.

Signed-off-by: Alexander Zarubkin <[email protected]>
@me21 me21 force-pushed the markdown-update-in-tooltip branch from c73d85a to f7afcb6 Compare April 2, 2024 14:41
@me21
Copy link
Contributor Author

me21 commented Apr 2, 2024

I'm sorry, I force-pushed new fix - it appears to be a one-liner 😄
But it introduces blinking of visible content on every update if Mermaid diagram is displayed inside Markdown element.

@me21 me21 changed the title Make markdown a descendant of html. Fix #2779 (markdown elements not updated if not displayed (e.g. inside tooltip or tab_panel)) Apr 2, 2024
@falkoschindler falkoschindler self-requested a review April 3, 2024 13:42
@falkoschindler falkoschindler added the bug Something isn't working label Apr 3, 2024
@falkoschindler falkoschindler added this to the 1.4.21 milestone Apr 3, 2024
@falkoschindler
Copy link
Contributor

Wow, that's a nice solution!
I just can't reproduce the blinking - or I don't know where to look. Do you have some example code to reproduce it?

@me21
Copy link
Contributor Author

me21 commented Apr 5, 2024

The following minimal example reproduces blinking for me:

textarea = ui.textarea()
markdown = ui.markdown(extras=['fenced-code-blocks', 'tables', 'mermaid'])
markdown.bind_content_from(textarea, 'value')

Now type the following into textarea:

```mermaid
graph LR;
    A-->B;
    A-->C;
```

You should see Mermaid diagram in Markdown. Now type something in textarea below that code block. You will see that markdown contents on each change will shortly blink with the code of the Mermaid diagram before being replaced with the diagram itself.

@falkoschindler
Copy link
Contributor

I think I found a rather nice solution: Instead of calling the "update" method with an HTML payload, we can simply update the element and handle the "updated" lifecycle hook on the client to render Mermaid diagrams.

I tested with the following snippet

with ui.textarea() as textarea:
    with ui.tooltip():
        ui.markdown(extras=['fenced-code-blocks', 'mermaid']).bind_content_from(textarea, 'value')

ui.markdown(extras=['fenced-code-blocks', 'mermaid']).bind_content_from(textarea, 'value')

as well as with the code from #278 (comment). All seems to work well. @me21 Would you like to try it out?

@falkoschindler falkoschindler changed the title Fix #2779 (markdown elements not updated if not displayed (e.g. inside tooltip or tab_panel)) Update Markdown elements even if invisible (e.g. inside tooltip or tab) Apr 5, 2024
@me21
Copy link
Contributor Author

me21 commented Apr 5, 2024

@falkoschindler works nicely!

Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you for your contribution, @me21! I think together we found a really nice solution to this rendering problem. 🙂

@falkoschindler falkoschindler merged commit 4628633 into zauberzeug:main Apr 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Markdown element is not updated if it is not displayed (for example in tooltip or tab_panel)
2 participants