Skip to content

Commit 9c7f920

Browse files
authored
fix(front): wait for markdown before rendering it (#387)
## 📝 Description Right now, the mermaid charts are being initialized on the page load. This can cause issues(charts not getting rendered) when the DOM is not yet ready. This PR fixes this issue. ## ✅ Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent b4d9345 commit 9c7f920

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

front/assets/js/report/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "github-markdown-css/github-markdown-light.css";
88
import * as toolbox from "js/toolbox";
99
import { useEffect, useState } from "preact/hooks";
1010

11-
Mermaid.initialize({ startOnLoad: true });
11+
Mermaid.initialize({ startOnLoad: false, theme: `default`, securityLevel: `strict` });
1212
const md = MarkdownIt().use(markdownItTextualUml as PluginSimple);
1313

1414
export default function ({ config, dom }: { dom: HTMLElement, config: any, }) {
@@ -69,6 +69,14 @@ const App = (props: { reportUrl: string, context: ReportContext, }) => {
6969
};
7070

7171
const MarkdownBody = (props: { markdown: string, }) => {
72+
useEffect(() => {
73+
if (props.markdown) {
74+
setTimeout(() => {
75+
void Mermaid.run();
76+
}, 100);
77+
}
78+
}, [props.markdown]);
79+
7280
return (
7381
<div
7482
className="markdown-body"
@@ -82,13 +90,13 @@ const ReportInstructions = (props: { context: ReportContext, }) => {
8290

8391
switch (props.context) {
8492
case ReportContext.Job:
85-
command = `artifact push job -d .semaphore/REPORT.md REPORT.md`;
93+
command = `artifact push job -f -d .semaphore/REPORT.md REPORT.md`;
8694
break;
8795
case ReportContext.Workflow:
88-
command = `artifact push workflow -d .semaphore/REPORT.md REPORT.md`;
96+
command = `artifact push workflow -f -d .semaphore/REPORT.md REPORT.md`;
8997
break;
9098
case ReportContext.Project:
91-
command = `artifact push project -d .semaphore/REPORT.md REPORT.md`;
99+
command = `artifact push project -f -d .semaphore/REPORT.md REPORT.md`;
92100
break;
93101
}
94102

0 commit comments

Comments
 (0)