Skip to content

fix: polyfill global CSSStyleSheet for mermaid rendering#20

Merged
pilat merged 1 commit into
mainfrom
fix/mermaid-cssstylesheet
Jun 21, 2026
Merged

fix: polyfill global CSSStyleSheet for mermaid rendering#20
pilat merged 1 commit into
mainfrom
fix/mermaid-cssstylesheet

Conversation

@pilat

@pilat pilat commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Why

CI has been flaky on test/mermaid-elk.test.ts with ReferenceError: CSSStyleSheet is not defined — five render tests fail together, but only sometimes (green most local runs, red on CI). It's a race, not a logic bug, and it surfaces now because we don't pin dependencies: a fresh npm install on the runner shifts timing just enough to trip it.

Root cause

@acemir/cssom (jsdom's CSS engine, pulled in transitively by isomorphic-mermaid) reads a bare global CSSStyleSheet while rendering. isomorphic-mermaid swaps window for svgdom's, which never defines that global, so depending on platform and timing the identifier is simply missing → ReferenceError. macOS almost always wins the race; the Linux runners almost always lose it.

Fix

Define CSSStyleSheet once, up front in loadMermaid(), before any diagram renders — using the real class from the same cssom jsdom uses, with a stub fallback if that transitive package ever moves. This is the same shape as the existing window.* shims a few lines below (Error, Math, …) that already paper over the svgdom environment.

Notes

  • The race only reproduces reliably on CI, so the real verification is the CI run on this PR going green — locally the suite was already passing.
  • No behavior change for the happy path: when the global is already present, the polyfill is a no-op.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pilat, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 7 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 043a0b26-23e3-4991-a1b2-eed9fdf8e1b4

📥 Commits

Reviewing files that changed from the base of the PR and between e2220a2 and 8d8c111.

📒 Files selected for processing (2)
  • src/acemir-cssom.d.ts
  • src/mermaid/render.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mermaid-cssstylesheet

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pilat pilat self-assigned this Jun 21, 2026
@pilat pilat merged commit 88b851b into main Jun 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant