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

flowchart node label disappears when too wide #5785

Open
DeD1rk opened this issue Aug 28, 2024 · 5 comments
Open

flowchart node label disappears when too wide #5785

DeD1rk opened this issue Aug 28, 2024 · 5 comments
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@DeD1rk
Copy link

DeD1rk commented Aug 28, 2024

Description

Since mermaid 11.0.0 (I tested that it does not occur on 10.9.1), on firefox, when I render a flowchart with somewhat long node labels, the node becomes an empty square.

However, on Chrome and Edge, it works fine, even with much larger content.

Steps to reproduce

  1. Create a flowchart
  2. Give a node a somewhat long label
  3. On firefox, the node's content disappears

Screenshots

image

See on the right that there is no big box of multiple lines of 'a', no subgraph title, and not the second node in the subgraph with '.iiiii(...)'. From the different number of a's vs i's needed to trigger this, it seems to have to do with the width, not the number of characters.

Doing the same on chrome, with even more text:
image

Code Sample

https://mermaid.live/edit#pako:eNrtVMFuwjAM_ZXIpyGVqm1aCNGEtGnXnbbTyA6hCTSCJihNxRji35emoEnTOm0745P17Oc4fomPUBohgcJqa_Zlxa1Dz_dMM43Q3thNky4Y8G_tdmnn18hQhMHr5wzReDzvXYw6tGmXa8t31QUbnPG5CkJCWVk6ZXRQp0MCNbsZZo66PKlFL-aSi9Qn310V-4-Wo8sIg5Le-aJjQBaD4_1BxpVyjddF_c7OnYRePCv-Gy08BoiglrbmSvhPf-xgBq6StWRAvSu43TBg-uTzeOvM00GXQJ1tZQTtTnAnHxT3l66Brvi28eiOa6BHeAM6zoq4mCRTgjGZZDjJpxEcgKYZiTFOSU7SPC9wmhWnCN6N8SWSmMzy2aSYTTHJkiQhRQRSKGfsY7-VwnIKZ7wEQt-INe26Ojdw-gCP2af3

Setup

  • Mermaid version: 11.0.0 (tested myself), 11.0.2 (on the online editor)
  • Browser and Version: Firefox (129.0)

Suggested Solutions

No response

Additional Context

I think this may relate to #5698, but I wanted to provide more complete information so opened a new ticket anyway.

@DeD1rk DeD1rk added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Aug 28, 2024
@dolt
Copy link

dolt commented Aug 30, 2024

Mitigation turn off htmlLabels when user agent is Firefox:

    flowchart: {
        htmlLabels: !navigator.userAgent.includes('Firefox'),
    },

When it doesn't render:

<foreignObject height="0" width="0">

When it does render:

<foreignObject height="24" width="197.43333435058594">

@dolt
Copy link

dolt commented Aug 30, 2024

The div being inserted (addHtmlLabel?) is not setting properties I would expect to be set:

<foreignObject height="0" width="0"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table; white-space: break-spaces; line-height: 1.5; max-width: 200px; text-align: center; width: 200px;"><span class="nodeLabel">

According to the code, white-space should be nowrap:

// Fix for firefox
div.style('white-space', 'nowrap');
div.attr('xmlns', 'http://www.w3.org/1999/xhtml');
return fo.node();
}

@DeD1rk
Copy link
Author

DeD1rk commented Aug 30, 2024

Thanks for investigating! Indeed setting htmlLabels: false fixes the content not showing up. The thing is though, in my actual use case, I'm relying heavily on html content. For example with nodes like this (though often much bigger, e.g. with code blocks inside, that cannot be migrated to just markdown):

s443("<span class='mermaid-step-header'><b>Placeholder</b> (Manual Step)</span><br>Type: XXXXXXXXXXXXXXXXXXXXX")

@jrobsonchase
Copy link

jrobsonchase commented Sep 5, 2024

I'm seeing this as well. Can confirm that the generated elements in the svg are different between the two browsers.

flowchart TD
	foo[aaaaaaaaaaaaaaaaaaaaaaa]
Loading

firefox:

<g transform="translate(0, 0)" style="" class="label"><rect></rect><foreignObject height="0" width="0"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table; white-space: break-spaces; line-height: 1.5; max-width: 200px; text-align: center; width: 200px;"><span class="nodeLabel"><p>aaaaaaaaaaaaaaaaaaaaaaa</p></span></div></foreignObject></g>

vs chrome:

<g transform="translate(-102.3359375, -12)" style="" class="label"><rect></rect><foreignObject height="24" width="204.671875"><div style="display: table; white-space: break-spaces; line-height: 1.5; max-width: 200px; text-align: center; width: 200px;" xmlns="http://www.w3.org/1999/xhtml"><span class="nodeLabel"><p>aaaaaaaaaaaaaaaaaaaaaaa</p></span></div></foreignObject></g>

Both from the mermaid-js live editor, but the github renderer is also affected.

PLukas2018 added a commit to PLukas2018/diffkemp that referenced this issue Sep 6, 2024
Github updated to the latest version of Mermaid (v11.1.0), this caused an issue with our graph in `README.md`. Specifically, it does not support `\n` for breaking lines anymore (probably caused by the [introduction of new string syntax](mermaid-js/mermaid#4271)).
This problem was fixed by replacing `\n` with `<br/>`

In the case of Firefox, there is a problem that for long labels the whole label has disappeared ([issue](mermaid-js/mermaid#5785)). In case of Chrome, long labels were autowrapped which caused not good rendering. To fix this problem the font size of clusters were decreased.
fedarko added a commit to fedarko/strainFlye that referenced this issue Sep 16, 2024
- Use <br/> instead of \n. For some reason, the latter apparently
  stopped working (both in the mermaid live editor and on github) --
  before \n would cause a linebreak, but now it just causes the
  literal text \n to show up in the flowchart (which is funny, but
  not what I want here...)

  See https://stackoverflow.com/q/51366763 for some discussion on
  this -- including an answer from 2022 where someone says that \n
  works!

- The newer version of mermaid introduced a bug where nodes with long
  labels just straight-up don't have the label show up anymore:
  mermaid-js/mermaid#5785 This impacted the
  "strainFlye call p-mutation" and "strainFlye call r-mutation" nodes.
  This will probably be fixed eventually on mermaid/github's side, but
  for now the workaround is just manually adding linebreaks to those
  node names.

Sidenote about that github issue link above: it includes a pointer to
PLukas2018/diffkemp@6aae129,
where someone else fixed the exact two problems above. this indicates
that these issues are due to the mermaid version update.
@sdyura
Copy link

sdyura commented Sep 19, 2024

this is really broken for me, when i try and do:

'''mermaid
flowchart TD
	CheckStatusForTriggerProcessingPath[CheckStatusForTriggerProcessingPath]-->CheckStatusForTriggerProcessingPath_CheckStatusForTrigger[CheckStatusForTriggerProcessingPath_CheckStatusForTrigger]
	TriggerSwitchingProcessingPath[TriggerSwitchingProcessingPath]-->TriggerSwitchingProcessingPath_ValidateRegistrationFlowStart[ValidateRegistrationFlowStart]
	TriggerSwitchingProcessingPath[TriggerSwitchingProcessingPath]-->TriggerSwitchingProcessingPath_TriggerSwitchingProcess[TriggerSwitchingProcessingPath_TriggerSwitchingProcess]
	CheckStatusForTriggerProcessingPath[CheckStatusForTriggerProcessingPath]-->TriggerSwitchingProcessingPath[TriggerSwitchingProcessingPath]
'''
flowchart TD
	CheckStatusForTriggerProcessingPath[CheckStatusForTriggerProcessingPath]-->CheckStatusForTriggerProcessingPath_CheckStatusForTrigger[CheckStatusForTriggerProcessingPath_CheckStatusForTrigger]
	TriggerSwitchingProcessingPath[TriggerSwitchingProcessingPath]-->TriggerSwitchingProcessingPath_ValidateRegistrationFlowStart[ValidateRegistrationFlowStart]
	TriggerSwitchingProcessingPath[TriggerSwitchingProcessingPath]-->TriggerSwitchingProcessingPath_TriggerSwitchingProcess[TriggerSwitchingProcessingPath_TriggerSwitchingProcess]
	CheckStatusForTriggerProcessingPath[CheckStatusForTriggerProcessingPath]-->TriggerSwitchingProcessingPath[TriggerSwitchingProcessingPath]
Loading

all i see is:
Screenshot 2024-09-19 at 1 43 49 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

4 participants