Skip to content

Build the box tree again on a media change without loading - #305

Open
eXpl0it3r wants to merge 1 commit into
feature/async-namingfrom
feature/load-then-build
Open

eXpl0it3r wants to merge 1 commit into
feature/async-namingfrom
feature/load-then-build

Conversation

@eXpl0it3r

@eXpl0it3r eXpl0it3r commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When an @media outcome flips on a resize, PerformLayout called RefreshMediaDependentCascade, which ran the whole SetHtmlAsync again and blocked on it with GetAwaiter().GetResult(). That's sync-over-async in the middle of a layout, usually on the UI thread, and it downloaded every <link> stylesheet and @font-face again, only to re-run the cascade.

As such DomParser now separates loading from building:

  • LoadAsync parses the document and does all the I/O, i.e. the stylesheets and the @font-face rules
  • BuildCssTree is synchronous and does the rest: the cascade for the current media, counters and the box tree fix-ups

SetHtmlAsync runs both, a media change only parses the cached HTML again and builds the tree from the already loaded CssData, without touching the network.

How to test this PR?

CI should succeed. MediaRefreshTests resizes across a breakpoint back and forth, checks that the matching rules apply each time, and that a linked stylesheet is only requested once. The second test fails without this change.

@eXpl0it3r
eXpl0it3r force-pushed the feature/load-then-build branch from 9fa176a to 14524c6 Compare November 26, 2026 20:49
@eXpl0it3r
eXpl0it3r added this pull request to stack #306 November 26, 2026 20:49
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