Keep @page declarations that follow a margin box - #200
Merged
TylerBrinks merged 1 commit intoJul 23, 2026
Merged
Conversation
Inside @page, a nested margin box (@top-center, @bottom-right, …) is parsed by CreateMarginStyle, whose inner FillDeclarations consumes the box's body through its closing '}' but leaves the ref token pointing at the box's own '{'. FillDeclarations then did `token = marginToken`, re-entering its loop on that stale token, so every declaration after the margin box - and any further margin box - was silently dropped: @page { @top-center { content: "h" } margin: 1cm } /* margin lost */ A margin box that comes last (the shape the existing test used) was unaffected, which is why this went unnoticed. Advance to the next real token with NextToken() instead. Declarations before the box already worked and are unchanged.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Inside
@page, any declaration that comes after a margin box is silently dropped:A margin box (
@top-center,@bottom-right, …, per CSS Paged Media 3 §6) is parsed byCreateMarginStyle, whose innerFillDeclarationsconsumes the box's body through its closing}. ButCreateMarginStyletakes the outer token byrefand leaves it pointing at the box's own{(whereCreateMarginSelectorleft it).FillDeclarationsthen did:so the loop re-entered on a stale token and skipped past everything up to the
@pageblock's own}— dropping any trailing declarations and any further margin boxes.A margin box that appears last in the block (the shape the existing
StyleSheetPageAtRulesAndPropertiestest uses) is unaffected, since there's nothing after it — which is why this went unnoticed.Fix
Advance with
NextToken()to the next real token after the consumed margin box. Declarations before a margin box already worked and are unchanged.Tests
3 tests in
Cases.cs: a declaration after one margin box, declarations both before and after, and two margin boxes followed by a declaration — asserting both the margin rules and the trailing longhands. All 3 fail onmaster. The existing@pagetest (margin box last) stays green, along with the other 1262 tests, and all seven target frameworks build with no new warnings.