Skip to content

CSS Grid algorithm 1/N: data structures#1923

Open
intergalacticspacehighway wants to merge 2 commits intofacebook:mainfrom
intergalacticspacehighway:css-grid-1-data-structures
Open

CSS Grid algorithm 1/N: data structures#1923
intergalacticspacehighway wants to merge 2 commits intofacebook:mainfrom
intergalacticspacehighway:css-grid-1-data-structures

Conversation

@intergalacticspacehighway
Copy link
Copy Markdown
Contributor

First in a series of PRs splitting the grid layout algorithm into reviewable chunks. Addresses feedback from #1894.

Summary

  • Rename style/GridTrack.h to style/GridTrackSize.h to match the type it defines and CSS grid naming spec.
  • Remove layout state fields (baseSize, growthLimit, infinitelyGrowable) from GridTrackSize — these belong in the algorithm layer, not the style definition
  • Add algorithm/grid/GridTrack.h, wraps GridTrackSize with layout state via composition (removed inheritance)
  • Add algorithm/grid/GridItem.h, represents a grid item with its resolved position (after autoplacement algorithm) and flags used during track sizing algorithm
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
yoga-website Ready Ready Preview, Comment Apr 1, 2026 4:55am

Request Review

@meta-cla meta-cla bot added the CLA Signed label Mar 27, 2026
@facebook-github-tools facebook-github-tools bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 27, 2026
size_t columnEnd;
size_t rowStart;
size_t rowEnd;
yoga::Node* node;
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.

Why does this need a full back-reference to the Yoga node?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We use node reference to call measure methods in TrackSizing algorithm. e.g. calling calculateLayoutInternal. Also to get style from node like item.node->hasDefiniteLength(), item.node->style().computeMarginForAxis etc in track sizing.

Copy link
Copy Markdown
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

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

This mostly LGTM. Just a couple questions.


namespace facebook::yoga {

// Represents a resolved grid track size during layout computation.
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.

nit: If all this after resolution step, can we make fields in struct const? That way, we would know, that it isn't mutated after-the-fact, during the layout algorithm, like some other structures.

Copy link
Copy Markdown
Contributor Author

@intergalacticspacehighway intergalacticspacehighway Apr 1, 2026

Choose a reason for hiding this comment

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

Yes, made the trackSize const. Other fields (baseSize, growthLimit, infinitelyGrowable) need to be mutable, added comments for them referring to the spec definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

2 participants