Repository navigation
feat(ai): add mermaid support to markdown - #780
Conversation
Siddhant-K-code
left a comment
There was a problem hiding this comment.
Checked this end to end with a headless Chromium harness that renders the real Markdown component under the same CSP as chat-view.ts. Lazy chunk loading and the script nonce work, with no CSP violations.
Inline comments cover four bugs I reproduced (HC Light theme, state reset while streaming, silent render failures, shared DOMPurify hooks) plus two nits.
Co-authored-by: Siddhant Khare <Siddhantkhare2694@gmail.com>
Deploying github1s with
|
| Latest commit: |
d896149
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://52757411.github1s-dld.pages.dev |
| Branch Preview URL: | https://dev.github1s-dld.pages.dev |
Co-authored-by: Siddhant Khare <Siddhantkhare2694@gmail.com>
|
@Siddhant-K-code Thank you for your review, I have made the fixes |
Siddhant-K-code
left a comment
There was a problem hiding this comment.
Re-reviewed at fd32042. All six earlier comments are addressed. I re-ran the original repros in headless Chromium:
- HC Light now gets the light theme, HC Dark still gets dark.
- The diagram, zoom, and scroll position survive text streaming after the block.
- Failures are logged and the reason shows in the tooltip.
- Links keep
noopener noreferrerafter a diagram renders.
Typecheck and all 27 tests pass. A themeCSS init directive stays scoped to the SVG and does not leak into the chat UI.
Two remaining UX issues inline, both with suggestions I applied and verified locally.
- Derive the toggle label from what is shown, disable it while a render is pending, and reset the selection when rendering fails so the next click retries. - Debounce re-renders while the source of an open diagram is still streaming, which avoids flicker and a render per token. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Siddhant-K-code
left a comment
There was a problem hiding this comment.
Approving. I pushed d896149 with the two fixes from my last review: the toggle label now matches the visible view, and an open diagram no longer re-renders on every streamed token. Typecheck, all 27 tests, and the webview build pass.
|
@conwnet - can you trigger a new release? |
Of course, I will do this in the next few hours |
Summary
Renders
```mermaidcode blocks in GitHub1s AI chat responses as diagrams.Diagramrenders the diagram,Sourceswitches back, and zoom in, zoom out, and reset controls appear while the diagram is shown.securityLevel: 'strict'. Invalid or incomplete diagrams keep the source visible and show the parse error in the button tooltip.Implementation notes
chat-view.ts:style-srcnow allows'unsafe-inline'because Mermaid injects styles without nonces.script-srcstays nonce-only.webview/index.ts: sets__webpack_nonce__so the lazily loaded Mermaid chunk passes the script CSP.helpers/markdown.ts: chat sanitization uses a private DOMPurify instance, so Mermaid's global DOMPurify hooks cannot change chat output. Links keeptarget="_blank"andrel="noopener noreferrer".Review
Reviewed in two rounds (first, second). Every finding was reproduced in headless Chromium against the webview CSP, and all fixes landed in this PR, the last in d896149. Typecheck, the 27 extension tests, and the webview build pass.
Landing in production
Merging to
masteronly updates a Cloudflare Pages preview. github1s.com deploys from the protectedreleasebranch.5ad1b60(v0.35.3)082d589(this PR)releaseis 3 commits behindmaster: #778 (KaTeX), #779 (KaTeX bump), and this PR.Next steps:
Build & TestandBuild & Test with VS Code buildon082d589to pass. They were still running when this was written.master→releasePR titledrelease 0.35.4(same patch cadence as release 0.35.3 #777) and merges it. Cloudflare Pages then deploys it to github1s.com.v0.35.4onreleaseand publish a GitHub release listing feat(ai): markdown supports for katex #778 and feat(ai): add mermaid support to markdown #780./static-<release merge sha>/bootstrap.js, then repeat the smoke test there.Rollback: roll production back to the previous deployment in Cloudflare Pages, or revert the merge on
release.