Skip to content

CSS Grid 2/9: Grid layout algorithm#1894

Open
intergalacticspacehighway wants to merge 3 commits intofacebook:mainfrom
intergalacticspacehighway:css-grid-2-algorithm
Open

CSS Grid 2/9: Grid layout algorithm#1894
intergalacticspacehighway wants to merge 3 commits intofacebook:mainfrom
intergalacticspacehighway:css-grid-2-algorithm

Conversation

@intergalacticspacehighway
Copy link
Copy Markdown
Contributor

Summary

  • Core grid layout computation and dispatch integration
  • Includes AutoPlacement.h, GridLayout.h/cpp, TrackSizing.h
  • CalculateLayout.cpp grid dispatch, CMakeLists.txt updates

Split from #1865. Depends on #1893. Merge after 1/9.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 25, 2026

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

Project Deployment Actions Updated (UTC)
yoga-website Ready Ready Preview, Comment Mar 5, 2026 6:58pm

Request Review

@meta-cla meta-cla bot added the CLA Signed label Feb 25, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 25, 2026
Summary:
Add the core grid layout computation and integrate it into the layout
dispatcher.

Includes:
- AutoPlacement.h: auto-placement algorithm for grid items
- GridLayout.h/cpp: grid layout entry point
- TrackSizing.h: track sizing algorithm
- CalculateLayout.cpp: grid dispatch block and #include
- CMakeLists.txt: add algorithm/grid/*.cpp glob
- React Native mirror of all C++ changes

Differential Revision: D93946253
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.

Been looking through this, for about an hour.

I think we still need to chunk this change into steps, of smaller concerns, to be able to give it a real review (vs trivial nits) which I feel like I ought to do, if we want to maintain this long term. It's been tricky for me to understand how everything connects. That might be an indication, it's worth documenting some of the newly added structures, if what they're doing isn't intuitive.

Could we build this up, in small parts of spec/behavior/structures at a time?


namespace facebook::yoga {

struct GridTrack : GridTrackSize {
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.

This organization is confusing to me. Why should style input, and calculations about it, have to be same/inherited object? We have two GridTrack.h, where the most public one is for GridTrackSize (maybe that should be GridTrackSize.h?).


namespace facebook::yoga {

struct TrackSizing {
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.

Keeping all this logic, in a single header, in a nested struct, without header explaining purpose of structure, is pretty hard for me to parse. Esp since everything is public. Is this to try to encapsulate since header only?

I think bc header only, we would also be needing to mark things as constexpr or inline.

float containingBlockHeight;
};

using CrossDimensionEstimator = std::function<float(const GridItem&)>;
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: we should avoid using std::function unnecessarily, compared to underlying functor type. It introduces overhead like heap reallocating capture group.

namespace facebook::yoga {

struct OccupancyGrid {
std::unordered_map<int32_t, std::vector<std::pair<int32_t, int32_t>>>
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.

std::unordered_map is quite expensive, heap allocating a node per inserted item. How many items is this usually be? Would it be better as a flat vector of items/binary searched vector? (sidenote, this is what std::flat_map is kinda meant to solve).

@intergalacticspacehighway
Copy link
Copy Markdown
Contributor Author

Could we build this up, in small parts of spec/behavior/structures at a time?

Sure @NickGerleman. yeah i thought this might be needed 😅. Will split it and also address above mentioned points in them.

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.

3 participants