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

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

Open
3 of 7 tasks
vshitov opened this issue Nov 21, 2022 · 5 comments
Open
3 of 7 tasks

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

vshitov opened this issue Nov 21, 2022 · 5 comments
Labels
apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee bug An error in the Docusaurus core causing instability or issues with its execution help wanted Asking for outside help and/or contributions to this particular issue or PR.

Comments

@vshitov
Copy link

vshitov commented Nov 21, 2022

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

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

  • Docusaurus version used: 2.2.0

Self-service

  • I'd be willing to fix this bug myself.
@vshitov vshitov added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Nov 21, 2022
@slorber
Copy link
Collaborator

slorber commented Nov 23, 2022

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

@slorber slorber added help wanted Asking for outside help and/or contributions to this particular issue or PR. and removed status: needs triage This issue has not been triaged by maintainers labels Nov 23, 2022
@mx3coding
Copy link

mx3coding commented Nov 23, 2022

@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

```
<!-- [end] add this to avoid the possible bug -->


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

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

</TabItem>

<TabItem value="tab-b">

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

</TabItem>
</Tabs>

@k0i
Copy link

k0i commented Dec 18, 2022

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)
```

</TabItem>

<TabItem value="tab-b">

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

</TabItem>
</Tabs>

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

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

</TabItem>

<TabItem value="tab-d">
```mermaid
graph LR
  d ---> z(42)
  e ---> z(42)
```

</TabItem>
</Tabs>

@pusolito
Copy link

pusolito commented Mar 28, 2023

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).

Tabs_Issue.mov

@slorber
Copy link
Collaborator

slorber commented Jun 8, 2023

While investigating #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 mermaid-js/mermaid#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.

@slorber slorber added the apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee label Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee bug An error in the Docusaurus core causing instability or issues with its execution help wanted Asking for outside help and/or contributions to this particular issue or PR.
Projects
None yet
Development

No branches or pull requests

5 participants