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

Switching light/dark theme will crash Mermaid diagrams. #2107

Closed
1 task done
hepheir opened this issue Dec 9, 2024 · 7 comments · Fixed by #2113
Closed
1 task done

Switching light/dark theme will crash Mermaid diagrams. #2107

hepheir opened this issue Dec 9, 2024 · 7 comments · Fixed by #2113
Labels
bug Something isn't working released Included or resolved in the release

Comments

@hepheir
Copy link
Contributor

hepheir commented Dec 9, 2024

Checklist

How did you create the site?

Generated from chirpy-starter

Describe the bug

Toggle light/dark theme switch button on the sidebar to produce this bug.

Steps To Reproduce

  1. enable mermaid on a post
  2. open a post which includes mermaid diagrams
  3. switch to light/dark theme by clicking toggle button on the sidebar

Expected Behavior

  1. some or all diagrams will print error message on them: "Syntax error in text"
Before switching light/dark modeAfter switching light/dark mode
Screenshot 2024-12-11 at 18 56 21 Screenshot 2024-12-11 at 18 56 26

Environment

  • Ruby: 3.3.0 [arm64-darwin24]
  • Jekyll: 4.3.4
  • Chirpy: 7.2.2

Furthermore..

  • Gem: 3.5.23
  • OS: macOS Sequoia 15.2
  • Arch: arm64 (Apple Silicon)
  • Run Command: ./tools/run

Anything else?

I can fix this quickly. #2108

@cotes2020
Copy link
Owner

Thank you for your report, but it lacks sufficient information.

Please provide the following details:

  1. The environment where the issue occurred
  2. The Mermaid code block that caused the issue

@lotusk08

This comment was marked as duplicate.

@hepheir
Copy link
Contributor Author

hepheir commented Dec 11, 2024

@cotes2020

  1. Sure. Here is the environment setup:
  • Ruby: 3.3.0 [arm64-darwin24]
  • Jekyll: 4.3.4
  • Chirpy: 7.2.2

I’ve also updated the description with screenshots and the environment information.

  1. As requested, here are the Mermaid code blocks:
```mermaid
graph LR
1((4)) --> 2((3)) --> 3((5))
```

...

```mermaid
graph LR
1((2)) --> 2((1)) --> 3((3))
```

...

```mermaid
graph LR
1((1)) -.-x 2((0)) -.-x 3((2))
```

...

```mermaid
graph LR
1((1)) -.-x 2((0)) -.-x 3((2))
1 ---> 3
style 1 stroke-width:4px
style 3 stroke-width:4px
```

@hepheir
Copy link
Contributor Author

hepheir commented Dec 11, 2024

I just enabled the browser debugger to take a deeper look at the code’s behavior.

As shown in the screenshot below, in the existing code, when refreshTheme() is called in _javascript/modules/components/mermaid.js, the previously backed-up Mermaid diagram is inserted via elem.textContent. During this process, the HTML < and > symbols are being escaped, which leads to incorrect insertion.

I believe this is the root cause of the issue.


Error description

1. Before Mermaid is rendered

Screenshot 2024-12-11 at 19 28 16

2. Immediately after switching the theme, during the rendering process (while refreshTheme() is being executed)

Screenshot 2024-12-11 at 19 27 32

> was replaced with &gt;

3. After rendering is complete, syntax errors occur

Screenshot 2024-12-11 at 19 27 39

@cotes2020
Copy link
Owner

  1. Sure. Here is the environment setup:
  • Ruby: 3.3.0 [arm64-darwin24]
  • Jekyll: 4.3.4
  • Chirpy: 7.2.2

I’ve also updated the description with screenshots and the environment information.

  1. As requested, here are the Mermaid code blocks:
    ...

Thank you, a complete bug report should be like this.

@cotes2020 cotes2020 added the bug Something isn't working label Dec 11, 2024
@cotes2020 cotes2020 linked a pull request Dec 11, 2024 that will close this issue
1 task
@hepheir
Copy link
Contributor Author

hepheir commented Dec 11, 2024

  1. Sure. Here is the environment setup:
  • Ruby: 3.3.0 [arm64-darwin24]
  • Jekyll: 4.3.4
  • Chirpy: 7.2.2

I’ve also updated the description with screenshots and the environment information.

  1. As requested, here are the Mermaid code blocks:
    ...

Thank you, a complete bug report should be like this.

I’ll make sure to provide more detailed information when creating issues in the future. Thank you!

@hepheir hepheir closed this as completed Dec 11, 2024
Copy link

🎉 This issue has been resolved in version 7.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Included or resolved in the release label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Included or resolved in the release
Projects
None yet
3 participants