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 diagram shift page when opening a link with anchor #9940

Open
3 of 7 tasks
AKiedis opened this issue Mar 11, 2024 · 1 comment
Open
3 of 7 tasks

Mermaid diagram shift page when opening a link with anchor #9940

AKiedis opened this issue Mar 11, 2024 · 1 comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: duplicate This issue or pull request already exists in another issue or pull request

Comments

@AKiedis
Copy link

AKiedis commented Mar 11, 2024

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

When opening the provided link in the step to reproduce, which points to a page containing a Mermaid diagram, the page shifts or scrolls due to the presence of the graphic, causing it not to land precisely at the anchor specified in the URL.
Every page with a mermaid diagram in my personal project suffer from the same issue.

Reproducible demo

No response

Steps to reproduce

  1. Open the following URL: https://docusaurus.io/fr/docs/next/markdown-features/diagrams#configuration
  2. Observe the page behavior as it loads.

Expected behavior

The page should load and position itself precisely at the anchor specified in the URL, allowing users to land directly at the intended section.

image

Actual behavior

Upon opening the URL, the page shifts or scrolls due to the presence of the Mermaid diagram, causing it to miss the anchor and land at an incorrect position.

image

The length of the shift depends on the length of the graphic.

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome and Firefox
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 11

Self-service

  • I'd be willing to fix this bug myself.
@AKiedis AKiedis 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 Mar 11, 2024
@slorber slorber added closed: duplicate This issue or pull request already exists in another issue or pull request and removed status: needs triage This issue has not been triaged by maintainers labels Mar 11, 2024
@slorber
Copy link
Collaborator

slorber commented Mar 11, 2024

Yes, Mermaid diagrams do not support server rendering in Node.js and produce layout shifts after React hydration. That is tracked in #8299

The only way we could fix this is to spawn a real browser at build time (like what https://github.com/remcohaszing/rehype-mermaid does) but I doubt it would be a good idea, and I'd prefer Mermaid to fix their actual server support instead.

I don't want to introduce official support for a thing we'll have to remove once Mermaid supports server-side-rendering. We provide a way to pass remark/rehype plugins, and a plugin API, so if you are really motivated to fix this issue, the problem can be worked around in userland.

We might explore adding support for D2 in the future, which looks like a modern alternative to Mermaid, supporting server-side-rendering (see discussions #9608)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: duplicate This issue or pull request already exists in another issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants
@slorber @AKiedis and others