You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(shared): theme-aware Markdown images accept whitespace around their media query - #46763
A theme-aware Markdown <picture> loses its dark (or light) variant when its media value has whitespace around the parentheses. In dark mode the user sees only the fallback image. COLOR_SCHEME_MEDIA allows whitespace inside the parentheses but not outside them. moveColorSchemeSourcesToImage then drops the <source> without copying its URL onto the <img>.
Deterministic repro on origin/main (7a9d2131fa45): an assistant message containing
goes through rehypePreserveImageSourceMeta (chat Markdown via apps/web/src/markdown/wordsHast.ts and CHAT_MARKDOWN_REHYPE_PLUGINS; image-source discovery via chatMarkdownImageSources).
Observed: the <img> comes out as <img src="/base.png" data-standalone> with no data-dark-src, and chatMarkdownImageSources returns ["/base.png"]. Dark appearance shows /base.png.
Expected: the <img> gets data-dark-src="/dark.png", the same as without the outer spaces. Dark appearance shows /dark.png and light appearance keeps /base.png.
Change
The media-query regex now allows optional ASCII CSS whitespace (space, tab, LF, FF, CR) before the opening and after the closing parenthesis. Everything after the match is unchanged, so web and Electron chat rendering and the shared image-source discovery all get the variant back.
Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
Added a padded-media row (" \t(prefers-color-scheme: dark) ") to the existing themed-picture test in packages/shared/src/markdownPipeline.test.ts.
Base: it fails because dataDarkSrc: "/dark.png" is missing from the <img> properties.
Not shown: before/after screenshots of the rendered chat in a dark-themed client, and the mobile client (it does not use this HAST pipeline).
Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).
Not shown
.github/pull_request_template.md:10 — Make the visual repro deterministic: seed two distinct, loadable PNGs in the workspace, use their relative paths in the assistant message, and assert that dark mode selects the base image on base and the dark image on head. Capture both states if running scenarios:prove.
.github/pull_request_template.md:26 — The supplied transcript confirms the targeted regression, but does not show check:changed tied to 9636fef02261b8400a6e384bbee5ea07c6dea678. Attach the SHA-stamped passing summary or state that the exit-0 result was reported, not independently verified.
Macroscope's review found this PR approvable — Theme-aware Markdown images now recognize color-scheme queries with surrounding whitespace. The change preserves existing source selection and URL sanitization, with no change to product defaults.
You can add or adjust custom eligibility rules. Learn more.
Reviewing files that changed from the base of the PR and between f97ba64 and cf329e1.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The color-scheme media matcher now accepts leading and trailing ASCII whitespace. A picture test checks a dark-mode source with padded whitespace.
Changes: Color-Scheme Media Matching
Layer / File(s)
Summary
Media matching and picture test packages/shared/src/markdownHast.ts, packages/shared/src/markdownPipeline.test.ts
The matcher accepts surrounding ASCII whitespace around dark and light media queries. The test checks the paragraph and picture structure, and verifies that /dark.png is attached as dataDarkSrc to the /base.png image.
Theme-aware Markdown images now keep their dark or light variants when the media query has surrounding whitespace. The change is small and covered by a test, so merge risk is minimal.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix and its scope: theme-aware Markdown images now accept whitespace around the media query. The raw summary confirms the regex change in markdownHast.ts and a matching test in mar…
Description check
The description covers the Problem, Change, Scope, and Verification sections. It gives a deterministic repro, the expected behavior, the regex change, the added test row, and the check result. It also…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the fix and its scope: theme-aware Markdown images now accept whitespace around the media query. The raw summary confirms the regex change in markdownHast.ts and a matching test in markdownPipeline.test.ts. It follows the conventional commit format from the template. The title is specific and accurate.
Full details: Description check
Explanation
The description covers the Problem, Change, Scope, and Verification sections. It gives a deterministic repro, the expected behavior, the regex change, the added test row, and the check result. It also states what it does not show. The Verification section cites a gist transcript and reports exit-0 for check:changed. The reviewer notes say the check:changed result is reported, not independently tied to a SHA. The author also lists visual repro gaps: no dark-mode before/after screenshots, and no seeded PNG repro. The template asks for before/after screenshots for UI changes. This change is a rendering fix, so the gap matters. The description is mostly complete, so it passes.
Resolution
Consider these follow-ups before merge, though none blocks the pass: attach before/after dark-mode screenshots or a seeded-PNG visual repro, as the template asks for UI-affecting changes; and attach the SHA-stamped check:changed summary, or state that the exit-0 result was reported and not independently verified.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between 7cf7446 and f97ba64.
Files selected for processing: 2
packages/shared/src/markdownHast.ts
packages/shared/src/markdownPipeline.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
On each commit, seed a fresh project with yellow base.png (“BASE (light)”) and blue dark.png (“DARK variant”). Replay one assistant message outside code fences with the padded picture and an unpadded control, both falling back to base.png. Open the thread in dark appearance, wait for decoded images, and capture; set light appearance and reopen the same thread, wait for decoded images, and capture. Check each image’s authored data-markdown-copy source.
Environment: real web client and server, Chromium on Linux, 1280×800; isolated fresh state on each commit, Replay (dev).
Scenario: Padded picture media selects the dark variant
Image-source discovery was not separately exercised; this proof covers rendered selection in dark appearance and fallback selection in light appearance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:XS0-9 changed lines (additions + deletions).vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A theme-aware Markdown
<picture>loses its dark (or light) variant when itsmediavalue has whitespace around the parentheses. In dark mode the user sees only the fallback image.COLOR_SCHEME_MEDIAallows whitespace inside the parentheses but not outside them.moveColorSchemeSourcesToImagethen drops the<source>without copying its URL onto the<img>.Deterministic repro on
origin/main(7a9d2131fa45): an assistant message containinggoes through
rehypePreserveImageSourceMeta(chat Markdown viaapps/web/src/markdown/wordsHast.tsandCHAT_MARKDOWN_REHYPE_PLUGINS; image-source discovery viachatMarkdownImageSources).<img>comes out as<img src="/base.png" data-standalone>with nodata-dark-src, andchatMarkdownImageSourcesreturns["/base.png"]. Dark appearance shows/base.png.<img>getsdata-dark-src="/dark.png", the same as without the outer spaces. Dark appearance shows/dark.pngand light appearance keeps/base.png.Change
The media-query regex now allows optional ASCII CSS whitespace (space, tab, LF, FF, CR) before the opening and after the closing parenthesis. Everything after the match is unchanged, so web and Electron chat rendering and the shared image-source discovery all get the variant back.
Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
" \t(prefers-color-scheme: dark) ") to the existing themed-picture test inpackages/shared/src/markdownPipeline.test.ts.dataDarkSrc: "/dark.png"is missing from the<img>properties.vp run check:changedexited 0 (format, lint, knip, typecheck, affected tests).chatMarkdownImageSourceson the repro input: base["/base.png"], head["/base.png","/dark.png"]. https://gist.github.com/saphid/0922d8ab3ee85b9d06fcb0dc3e272a8aNot shown: before/after screenshots of the rendered chat in a dark-themed client, and the mobile client (it does not use this HAST pipeline).
Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).
Not shown