Skip to content

Evaluate the media query list in matchMedia against the render device - #228

Merged
FlorianRappl merged 1 commit into
AngleSharp:develfrom
lahma:fix/match-media-evaluation
Sep 2, 2026
Merged

Evaluate the media query list in matchMedia against the render device#228
FlorianRappl merged 1 commit into
AngleSharp:develfrom
lahma:fix/match-media-evaluation

Conversation

@lahma

@lahma lahma commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

CssMediaQueryList.ComputeMatched returned a constant false, so window.matchMedia(...).IsMatched answered false for every query - even all and the empty query, which always match; this was reported in AngleSharp/AngleSharp#1307. It now validates the media list against the browsing context's IRenderDevice through the same MediaListExtensions.Validate path that @media rules already take for the cascade, falling back to DefaultRenderDevice when no device is registered, exactly as GetComputedStyle does. Tests cover media types, min-width/max-width/min-height, and, only, not, an unknown feature and the empty query, per https://drafts.csswg.org/mediaqueries-4/#mq-list and https://drafts.csswg.org/cssom-view/#dom-window-matchmedia.

CssMediaQueryList.ComputeMatched returned a constant false, so
window.matchMedia(...).IsMatched answered false for every query,
including "all" and the empty query, which always match. It now
validates the media list against the render device from the browsing
context, reusing the very same evaluation that @media rules already go
through for the cascade, and falls back to DefaultRenderDevice when no
device is registered - the same fallback GetComputedStyle uses.

Reported in AngleSharp/AngleSharp#1307.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NqCcJrL3MJecCPRBMQsZyC

@FlorianRappl FlorianRappl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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.

2 participants