Skip to content

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

Merged
eXpl0it3r merged 1 commit into
masterfrom
feature/load-then-build
Dec 2, 2026
Merged

eXpl0it3r merged 1 commit into
masterfrom
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
Base automatically changed from feature/async-naming to master December 2, 2026 08:08
@eXpl0it3r
eXpl0it3r force-pushed the feature/load-then-build branch from 14524c6 to a70c00d Compare December 2, 2026 08:08
@eXpl0it3r
eXpl0it3r force-pushed the feature/load-then-build branch from a70c00d to 633f778 Compare December 2, 2026 08:36
@eXpl0it3r
eXpl0it3r merged commit eda59e4 into master Dec 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant