Skip to content

Grid: lay subgrids out in their parent tracks - #2673

Merged
kane50613 merged 7 commits into
grid/named-linesfrom
feat/grid-subgrid
Nov 20, 2026
Merged

kane50613 merged 7 commits into
grid/named-linesfrom
feat/grid-subgrid

Conversation

@kane50613

@kane50613 kane50613 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Why

grid-template-columns: subgrid laid out as none without a warning, so a nested grid sized its own tracks and rows never lined up across cards. WPT css-grid/subgrid passed 34 of 89, and those only because their references ignored subgrid too.

What

A function-level port of Blink's subgrid support:

  • Style: subgrid <line-name-list>? parses and computes as Blink's ComputedGridTrackList, and Tailwind gains grid-cols-subgrid.
  • Tree: GridSizingTree, GridLayoutTree, GridLayoutSubtree, and SubgridMinMaxSizesCache live in the new grid_sizing_tree.rs, built by BuildGridSizingSubtree and ForEachSubgrid.
  • Lines and placement: GridLineResolver::for_subgrid merges the parent's line names and areas, and placement clamps items to the subgrid's area.
  • Sizing: subgridded items size the parent's tracks with their extra margins, and ComputeSubgridIntrinsicSize sizes a subgrid's standalone axis. A subgrid's gap replaces its parent's in its span.
  • Layout: a subgrid receives its tracks through ConstraintSpace::grid_layout_subtree and skips its own sizing, as Blink returns early in ComputeGridGeometry.

The code marks where it departs from Blink. takumi lays out horizontally only, so every subgrid is parallel to its parent, and a subgrid keeps its placement on its sizing-tree node since takumi has no LayoutGrid.

Results

  • WPT subgrid passes 69 of 89. The rest need vertical writing modes, last baseline, container queries, or sticky positioning.
  • The full run passes 10,219, up from 10,188. Eight grid-lanes subgrid tests stop passing: their references now lay out a real subgrid, which an unsupported grid-lanes container cannot match.
  • grid_subgrid pins rows lined up across three cards and a strip using named lines and its own gap. Every other golden stays byte-identical.
  • A 2,000-item grid renders in a median 56.6 ms against 56.2 ms on master over 30 alternating runs.

Stacked on the named-line PR.

Follow-up

The approximations are gone except horizontal-only layout:

  • Subgrids take part in their grid's baselines, measured in track sizing and in final layout, with Blink's deferred standalone-axis pass.
  • Items join the major or minor baseline group as Blink decides, and CreateSubgridBaselines swaps them for a subgrid running opposite its root.
  • Placement and SubgridMinMaxSizesCache live on a new layout_grid.rs node that persists across layout passes, as on Blink's LayoutGrid.

WPT, goldens, and timing are unchanged by the follow-up: every subgrid baseline test still failing also needs a vertical writing mode.

`grid-template-columns`, `grid-template-rows`, `grid-template`, and Tailwind's `grid-cols-subgrid` take `subgrid <line-name-list>?`, as Blink's ConsumeGridTrackList does, with one `auto-fill` name repeater at most.
Port Blink's subgrid support. GridSizingTree holds a grid and its nested subgrids, BuildGridSizingSubtree appends the items a root grid sizes, the line resolver merges the parent's line names and areas, placement clamps to the subgrid's span, CreateSubgridTrackCollection and CreateSubgridBaselines give a subgrid its parent's tracks with its margin, border, padding, and gap, and the subgrid lays out in the GridLayoutSubtree its constraint space carries.
Eight grid-lanes subgrid tests no longer pass: they passed only because both sides ignored `subgrid`, and their references now lay out a real subgrid that the unsupported grid-lanes container cannot.
@kane50613
kane50613 added this pull request to stack #2674 November 20, 2026 09:15
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Pre-merge checks: Passed 3

Check name Status Explanation
Chromium Parity Passed The pull request changes rendered and measured output. It adds subgrid track support, subgrid sizing, and placement, so the check's fallback condition applies. The condition passes because the pull …
Golden Fixture Passed The pull request changes rendered output. Subgrid previously laid out as none, and the new code lays out subgrids in their parent's tracks. The PR description reports WPT subgrid moving from 34 to…
Refactor Stays Separate Passed The check applies only to commits described as a refactor, rename, or move. It fails a commit that both restructures code and changes output. Evidence: - The PR title is "Grid: lay subgrids out in the…
Full details: Chromium Parity

Explanation

The pull request changes rendered and measured output. It adds subgrid track support, subgrid sizing, and placement, so the check's fallback condition applies. The condition passes because the pull request description and the changed code name the Blink source the new behavior follows. - Pull request description: It calls the work "a function-level port of Blink's subgrid support." It names Blink's BuildGridSizingSubtree, ForEachSubgrid, ComputeSubgridIntrinsicSize, ComputeGridGeometry, and CreateSubgridBaselines. It also documents the approximation: "takumi lays out horizontally only, so every subgrid is parallel to its parent," and says "The code marks where it departs from Blink." - Changed code: In this checkout, the grid files carry Blink source links and notes, for example grid_style.rs ("Blink's GridTrackList", "Blink's ComputedGridTrackList") and grid_track_collection.rs ("Blink's GridTrackCollection"). The subgrid files are grid_sizing_tree.rs and grid_layout_algorithm.rs. I did not read every subgrid block, so this rests on the sampled files and the description. Either evidence source alone satisfies the condition. Both are present.

Full details: Golden Fixture

Explanation

The pull request changes rendered output. Subgrid previously laid out as none, and the new code lays out subgrids in their parent's tracks. The PR description reports WPT subgrid moving from 34 to 69 passing and a total rise from 10,188 to 10,219. The check therefore requires a golden file under one of the listed fixtures-generated directories that shows the change. The PR-specific commit ee11c18 ("Grid: lay subgrids out in their parent's tracks") adds takumi/tests/fixtures-generated/grid_subgrid.svg and grid_subgrid.webp, with source takumi/tests/fixtures-html/grid_subgrid.html. The HTML uses grid-template-rows: subgrid on cards and grid-template-columns: subgrid on a strip. The SVG output shows the aligned rows. This satisfies the "adds a golden file that shows the change" condition. The PR's own commits (ee11c18, e826451, 372f774) modify no existing golden file. The larger origin/master...HEAD diff shows other golden changes, but those come from the base grid/named-lines stack and merges, not from this PR. A search of the test inputs found no other subgrid fixtures whose output could change. The WPT pass-count changes concern reference tests, not golden fixtures. I did not run the renderer, so the byte-identity claim for other goldens rests on the diff evidence and the PR description.

Full details: Refactor Stays Separate

Explanation

The check applies only to commits described as a refactor, rename, or move. It fails a commit that both restructures code and changes output. Evidence: - The PR title is "Grid: lay subgrids out in their parent tracks". The PR description calls the work a feature port of Blink subgrid support. It does not describe the PR as a refactor, rename, or move. - The local checkout has the PR commits. Commit subjects include "Grid: port subgrid baselines and keep LayoutGrid's caches on the node" (e826451) and "Grid: leave named lines to their own changeset" (1482ba7). These describe feature work and a changeset split, not a refactor. The PR description also says the follow-up leaves WPT, goldens, and timing unchanged. - Commit 372f774 has "move" in its subject: "describe the nested subgrid line move as Blink's behavior". The commit changes 2 insertions and 1 deletion in grid_line_resolver.rs. It describes behavior and does not move code. It changes no golden file, so it would pass the check even under a broad reading. - The PR description states that grid_subgrid is the only new golden, and that every other golden stays byte-identical. I did not run the golden tests. This verdict relies on the author's stated results and the commit contents read above. No commit in the PR is described as a refactor, rename, or move that changes output. The check does not apply, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

takumi leaves a nested subgrid's lines past the parent's auto repeater where they are, exactly as Blink's ExpandAutoRepeatTracksFromParent does, so the note no longer calls it an approximation.
Port Blink's major and minor baseline groups (GridTrackBaselines, GetTrackBaseline, GetExtraMarginForBaseline, the minor branch of ComputeBaselineOffset and GridBaselineAccumulator), CreateSubgridBaselines for subgrids running opposite to their root grid, subgrids measured from their layout subtree in ComputeGridItemBaselines, and the deferred ResolveBaselinesInStandaloneAxes pass. A grid's placement and a subgrid's SubgridMinMaxSizesCache now live on its layout node, as on Blink's LayoutGrid, and persist across its layouts.
@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

@takumi-rs/helpers

bun add https://pkg.pr.new/kane50613/takumi/@takumi-rs/helpers@2673

@takumi-rs/image-response

bun add https://pkg.pr.new/kane50613/takumi/@takumi-rs/image-response@2673

takumi-js

bun add https://pkg.pr.new/kane50613/takumi/takumi-js@2673

@takumi-rs/core

bun add https://pkg.pr.new/kane50613/takumi/@takumi-rs/core@2673

takumi-paint

bun add https://pkg.pr.new/kane50613/takumi/takumi-paint@2673

takumi-pdf

bun add https://pkg.pr.new/kane50613/takumi/takumi-pdf@2673

@takumi-rs/wasm

bun add https://pkg.pr.new/kane50613/takumi/@takumi-rs/wasm@2673

commit: 8f74b0e

@kane50613
kane50613 merged commit 4db3a6d into master Nov 20, 2026
27 checks passed
@kane50613
kane50613 deleted the feat/grid-subgrid branch November 20, 2026 09:41
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