facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.34k stars 8.46k forks source link

Mermaid in tabs. The arrows are not displayed in the second tab #8357

Open vshitov opened 1 year ago

vshitov commented 1 year ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Discussion from https://stackoverflow.com/questions/74474982/mermaid-in-tabs

The arrows are not displayed in the second tab It works here https://docusaurus.io/tests/pages/diagrams#mermaid-in-tabs

I have:

a) In "tab-a", the arrows are displayed:

Tab a

b) But in "tab-b", the arrows are not displayed:

Tab b


Version of docusaurus: 2.2.0
Type files: .md or .mdx

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="tab-a">

The following mermaid diagram is shown:

```mermaid
graph LR
  a ---> c(10)
  b ---> c(10)
```

</TabItem>

<TabItem value="tab-b">

This mermaid diagram is not displayed:

```mermaid
graph LR
  d ---> z(42)
  e ---> z(42)
```

</TabItem>
</Tabs>

Reproducible demo

No response

Steps to reproduce

  1. Create new file .md
  2. Add mermaid diagram graph LR in two tab

Expected behavior

Arrows are displayed in all tabs

Actual behavior

The arrows are not displayed in the second tab

Your environment

Self-service

slorber commented 1 year ago

Can reproduce, not sure why it happens 😅 if anyone wants to investigate. Not even sure it's a Docusaurus bug.

A good-enough temporary workaround is <Tabs lazy>, which will only render one tab at a time

mx3coding commented 1 year ago

@slorber , I used this proposed workaround: https://stackoverflow.com/a/74479494/5734097 Maybe it helps to find the solution, because it looks like its missing some kind of initialization.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Mermaid in tabs

<!-- [start] add this to avoid the possible bug. Note: the empty line before [```] is necessary -->
```mermaid
flowchart TD
```mermaid graph LR a ---> c(10) b ---> c(10) ``` ```mermaid graph LR d ---> z(42) e ---> z(42) ```
k0i commented 1 year ago

Hello everyone!

I did a little survey about this issue.

<path marker-end="url(#flowchart-pointEnd)" style="fill:none;" ...></path>

The above element is a child of g element, that has an edgePath class and describes paths between nodes. And I noticed that url(#flowchart-pointEnd) 's result may refer to a different component https://w3c.github.io/csswg-drafts/css-values/#local-urls

Снимок экрана_2022-12-18_11-03-14

If I changed the second tab's url function to url(#flowchart-pointEnd2) and modify the element's id, all of elements are correctly rendered. Снимок экрана_2022-12-18_11-08-22

On top of that, if I delete the second tab's flow-chart-pointEnd element, it brings no change and it may reinforce the hypothesis that the url function directs to a different element.

But, I'm still not sure why inserting another element that has flowchart-pointEnd element into the outside of the tab works as a workaround....

This gif may also indicates that the url function interfere with each other.... out


import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Mermaid in tabs

<Tabs>
<TabItem value="tab-a">

```mermaid
graph LR
  a ---> c(10)
  b ---> c(10)

```mermaid graph LR d ---> z(42) e ---> z(42) ```

```mermaid graph LR a ---> c(10) b ---> c(10) ``` ```mermaid graph LR d ---> z(42) e ---> z(42) ```
pusolito commented 1 year ago

I have a similar issue, but with a different component in a second tab. I'm using the kotlin-playground component, which is based on CodeMirror. My code item does not render properly in the second tab (it is partially initialized). But it works fine if I use lazy tabs. One thing to note is that resizing the browser window causes the component to update like it does when first clicked, but it is still not properly displayed after this. Using a lazy tab completely eliminates this issue. But it is not a good option for my use case, since that means tabs are created every time they are selected (not just the first time, as you'd imagine).

https://user-images.githubusercontent.com/9815928/228273231-c5352f3d-a1e9-4a8c-99cb-4541df91c10a.mov

slorber commented 1 year ago

While investigating https://github.com/facebook/docusaurus/issues/9032, found out that Mermaid is not great at rendering diagrams concurrently, and we should ensure to render them sequentially one after the other.

See https://github.com/mermaid-js/mermaid/issues/3577

I suspect we'll have to build fancy things like a rendering queue so that different components (in this case tabs) do not attempt to render diagrams concurrently.