Skip to content

Review: OpenPencil's patches on Taffy affd437f - #2

Open
dannote wants to merge 110 commits into
review/basefrom
openpencil/taffy
Open

dannote wants to merge 110 commits into
review/basefrom
openpencil/taffy

Conversation

@dannote

@dannote dannote commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Review only, not to be merged. Every patch on openpencil/taffy was pushed without review; this pull request shows all of them against the Taffy commit the branch starts from, affd437f (the commit Blitz pins), so they can be reviewed together. Fixes that come out of the review go to openpencil/taffy as their own pull requests.

What changed

  • Flexbox: a growing item's cross size transferred through its aspect ratio (cherry-picked from Fix flexbox aspect-ratio min sizing and floated flex container sizing DioxusLabs/taffy#1081, fixing aspect_ratio is not respected in flex layouts DioxusLabs/taffy#804), with Chrome-generated fixtures.
  • Flexbox: a row's line, and so a row without a height, sized from that transferred cross size, as Chrome does; columns unchanged. Fixtures aspect_ratio_flex_{row,column}_grow_sizes_auto_container.
  • openpencil/: a crate that lays a whole tree out from fixed-size f32 records in one call (src/lib.rs), its TypeScript host (host/index.ts) and tests, build.ts, notices from cargo-about, and the workflow that releases every push as taffy-<commit>.
  • Host changes since: margins in the records, taffy.wasm shipped beside taffy.js, records written in place into reused module buffers (9c9fcf8), and measure errors caught inside the import with the stack pointer restored after a trap (cfe209d).
  • OPENPENCIL.md lists the patches.

AI assistance

Models: Claude Opus 5.5

Validation

  • cargo test: Taffy's generated fixture tests pass, including the new ones (6681).
  • openpencil/: cargo clippy -D warnings, bun build.ts, and host tests pass; every commit's release built in the workflow.
  • feat: lay out auto layout with Taffy instead of the Yoga fork open-pencil#2016 pins taffy-9c9fcf89… and runs its auto layout on it: Core's layout tests pass, and Material 3 lays out closer to Figma's saved geometry than Yoga did.

Summary by CodeRabbit

  • New Features
    • Added a WebAssembly-based layout package with a TypeScript API for building layout trees and calculating results.
    • Added automated builds that publish commit-specific releases with downloadable artifacts.
  • Bug Fixes
    • Improved flexbox sizing for growing items with aspect ratios, including cases involving size constraints, padding, and siblings.
  • Documentation
    • Added setup, build, testing, release, and compatibility details for the new package.

nicoburns and others added 30 commits October 27, 2026 10:01
* Add cephal to benchmarks

* Remove README update
…ioxusLabs#1386)

* Make find_content_slot avoid floats beside the content's full height

* Start the merged content slot insets from the containing block insets

* Merge the content slot's own segment outside the loop
* Record zero-height floats as zero-height segments

* Fold zero-height float placement into the general float placement path
…sLabs#1379)

Bumps [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action) from 24.2.0 to 25.0.0.
- [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases)
- [Commits](DavidAnson/markdownlint-cli2-action@v24.2.0...v25.0.0)

---
updated-dependencies:
- dependency-name: DavidAnson/markdownlint-cli2-action
  dependency-version: 25.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Halves the size of Baselines (16 -> 8 bytes) and of its share of
LayoutOutput. The fields become private, read through first()/last().
PerformLayout computed both container baselines unconditionally, and with
items that have no baseline the "first item that has a baseline" step
scanned the whole startmost and endmost line (or row) of every container,
slowing layouts that never read a baseline by 2-7%. Nothing reads the
baselines of a full layout unless it requested them, so PerformLayout now
honours `requested_baselines` like ComputeSize does: containers forward
the request to the items that can provide the baseline, and final-layout
cache entries record which baselines they hold.
Baseline-aligned items do not stretch, so the hypothetical cross size the
measurement is done at is also the item's final size and (as the cache key
ignores available space once both dimensions are known) the final layout
pass hits the measurement's final-layout entry. A ComputeSize measurement
lives in the other cache pool and cannot serve the final layout, so every
participant was laid out twice.
Items that were not asked for baselines can never provide the container's,
so the final layout pass skips the scroll-container clamping/synthesis and
the NaN packing for them. Also inline the grid area lookup.
Track-vec indexes interleave gutters and tracks, so an item spanning only the
last row has `end == start + 2`, not `start + 1`. The old check never matched,
so the container's last baseline skipped the row's baseline-sharing group and
took the last baseline of the last item in grid order instead.
nicoburns and others added 30 commits November 13, 2026 11:23
…k merging and cell max-width (DioxusLabs#1393)

* Table layout: distribute spanning cells with the width distribution algorithm and merge empty columns

A cell spanning several columns now shares its min-content and max-content widths out over them
with the same guesses the table's width goes through, narrower spans first. In an auto table, a
column that no cell starts in and no column box gives a width merges into its neighbours and takes
no border-spacing. A cell's max-width also clamps its min-content width.

* Table layout: start a new track at every column box

Two adjacent <col> elements are separate tracks even when no cell starts in the second one, as
Chrome does; only the columns inside one column box's span merge.

* Table layout: keep the spanned range for the fixed-layout colspan path
…ves against the grid width

A cell's `height` was passed to block layout as a known dimension when
measuring row heights, so the row never grew to content taller than it.
Measure the content height instead and apply `height`/`min-height` as
a minimum on the row (CSS 2.1 §17.5.3).

Cell percentage padding and border were resolved against the table's
containing block width in the baseline fallback and the stored Layout,
while block layout resolved them against the table's width. Resolve
them against the grid width everywhere, matching Chrome.
… dead span code

A fixed table measured the max-content width of every spanning cell, but
only reads that measure when the cell has a length width, so an
unconstrained spanning cell had its content laid out for nothing. Only
measure cells with a specified width, as the comment already claimed.

The fixed-layout `distribute` branch in the span loop could never run,
since the fixed branch before it always continues. Remove it, along with
`distribute`, which had no other caller.
Fixed and auto layout share little of column measurement beyond the
column and column-group widths: fixed reads only the first row, never
measures content, shares spans out evenly and scales percentages down.
Interleaving the two behind `is_fixed` checks hid the bugs fixed in the
previous commit.

Split `measure_columns` into `new_columns`, which applies the column box
widths for both, and `measure_fixed_layout_columns` and
`measure_auto_layout_columns`, mirroring the Phase 3 column resolvers.
No change in behaviour.
`Group` and `Grid.groups` predate column groups, so `group` came to mean
a row group in some places and a column group in others: `Row.group` and
`ColumnBox.group` index different lists, and a local `group` was a
column group, a row group or a bool depending on the line.

Rename `Group` to `RowGroup`, `groups` to `row_groups`, `Row.group` to
`row_group`, `ColumnBox.group` to `column_group` and `group_row_range`
to `row_group_range`, and name the locals after the kind of group they
hold. No change in behaviour.
…t the empty table

Gather the table's resolved padding, border, sizes, border-spacing,
layout mode and direction into a `TableConstants` built by
`compute_constants`, as flexbox does with `AlgoConstants`, so the phases
can be split out of `compute_table_layout` without each taking a dozen
scalars. Move the layout of a table with no rows and no columns into
`compute_empty_table_layout`.

No change in behaviour.
Move the table's used width (grid min/max, shrink-to-fit, clamps and
CAPMIN) into `determine_table_width` and `visibility: collapse` on
columns into `collapse_columns`, leaving Phase 3 in
`compute_table_layout` as the sequence of its steps.

No change in behaviour.
Move each step of Phase 4 into a function of its own: laying the cells
out at their final widths (`measure_cell_heights`), baseline alignment
(`align_cell_baselines`), the rows' own heights (`apply_row_heights`),
growing the rows for rowspans, row groups and the table
(`distribute_row_heights`), `visibility: collapse` on rows
(`collapse_rows`) and fallback baselines (`synthesise_row_baselines`).

No change in behaviour.
Move the track positions into `position_tracks`, which returns them as a
`GridGeometry`, and lay out the column boxes, the row groups and rows,
the cells and the hidden children in functions of their own. The cells'
out-of-flow descendants are collected by `layout_cells` and appended in
the same order as before.

`compute_table_layout` now reads as the sequence of the algorithm's
phases and its early returns.

No change in behaviour.
…le layout)

# Conflicts:
#	CHANGELOG.md
#	src/compute/block.rs
#	src/compute/flexbox.rs
#	src/compute/mod.rs
#	src/compute/oof.rs
#	src/tree/cache.rs
#	src/tree/layout.rs
#	src/tree/traits.rs
…usLabs#804)

A flex item with aspect-ratio whose main size comes from flex-grow takes its
cross size from the flexed main size through the ratio, in rows and columns,
with a max-width clamp and beside a sibling. Expectations generated by gentest
in Chrome; the four fixtures added with the fix are regenerated alongside.

(cherry picked from commit 468c949)
openpencil/ builds Taffy into a WebAssembly module that lays out a whole tree
from fixed-size records in one call, with a TypeScript host around it. Every
push to openpencil/taffy releases it as taffy-<commit> for
open-pencil/open-pencil to pin.

(cherry picked from commit 27fc2ef)
The hypothetical cross size of an item whose cross size is transferred
through its aspect ratio now follows its used main size, as section 9.4
step 7 says, so a row without a height takes the height Chrome gives it
rather than 0. A column's width still comes from intrinsic sizes, as in
Chrome. The transfer is shared with determine_used_cross_size.

(cherry picked from commit fc4f0ac)
taffy.js loads taffy.wasm from new URL('./taffy.wasm', import.meta.url):
browsers fetch it, compiling it as it downloads when it is served as
WebAssembly, bundlers such as Vite emit it as an asset, and Node and Bun
read it from disk. Embedded as Base64 it cost 135 KB gzipped in the
JavaScript that loads it, against 78 KB for the module with brotli.

(cherry picked from commit 1f71b6e)
…'s memory

The host built each record in a JS Float32Array through a subarray view, allocated arrays and
closures per node for edges and grid fields, copied the batch into the module, and allocated and
freed it on every call. It now keeps the record and track buffers in the module between calls,
grown when a tree needs more, and writes every field in place. Host time per node falls from
about a third of a call to under 5%; a 11-node tree lays out 22% faster, 6000 nodes 15%.
A measure function laying out another tree now throws instead of corrupting the call.

(cherry picked from commit 9c9fcf8)
…raps

An exception from a measure function unwound through the module's frames, which never put Rust's
shadow stack pointer back; a few hundred such calls ran it off the end of the stack and every
later call failed with an out-of-bounds access (open-pencil/open-pencil#1928, seen with Yoga).
The measure import now catches the error, answers zero, and the call rethrows it once the module
has returned. The module exports __stack_pointer, and a call that traps, such as on a stack
overflow from a very deep tree, puts it back before rethrowing.

(cherry picked from commit cfe209d)
…nsic heights, and a width

Chrome 157: a content-box item's min-width transfers its height without its padding; an item with
height: max-content keeps its content height; a growing item with a width sizes an auto-height row
from its used width.

(cherry picked from commit 83a09e8)
…r flexing

Found in review (#2). Three cases laid out differently from Chrome:

- Min and max sizes include padding and border under box-sizing: content-box, and were transferred
  through the aspect ratio as they were; they now lose that before the ratio applies and get it
  back after, for the hypothetical cross size and for the used one.
- A cross size of min-content, max-content, or fit-content resolves to none, as auto does, and was
  replaced by the transferred size; only auto, or a percentage of an indefinite size, transfers.
- A row's line took a growing item's transferred cross size only when the item had none before
  flexing, so an item with a width kept the height of its unflexed width.

Fixtures from the previous commit; the rest of the suite passes.

(cherry picked from commit 0c6c1d9)
The tests import the built out/taffy.js, which a fresh checkout does not have, so tsc failed
before any test ran; CI only passed because it builds first. Found in review (#2).

(cherry picked from commit 939d2f7)
* openpencil: change the branch only through reviewed pull requests

Every push to openpencil/taffy cuts a release, so changes now come as pull requests reviewed by
CodeRabbit and a maintainer. AGENTS.md holds the rules for the branch: pull requests, fixtures and
upstreaming for layout fixes, and the record format and exception rules of openpencil/. The
OpenPencil workflow also builds and tests pull requests against the branch, and releases only on
push.

* Review pull requests into openpencil/ branches with CodeRabbit

CodeRabbit reviews only pull requests into the default branch unless told otherwise, and the
fork's work goes into its openpencil/ release branch.

* Release only on push, not on a dispatched run

A run started by hand can name any branch, so it could release a commit that never merged.

(cherry picked from commit 7bd33d4)
…io transfer

An item with a width and height: max-content still got the height its width transfers
through the ratio as its initial size, which then skipped measuring it, so the keyword was
lost. The initial size now transfers only to a cross size that is not a sizing keyword.
Fixture aspect_ratio_flex_row_max_content_height_with_width_is_kept (Chrome 157). Found in
review (#3).

(cherry picked from commit 7c3bb52)
Move the base to Taffy's table layout with requested baselines
A LayoutNode can carry its first baseline, such as a text's first line, which the binding gives Taffy as the leaf's, so baseline alignment places text by its baseline, nested boxes by their first child's, and each wrapped line by its own. A leaf without one still aligns by its bottom edge.
openpencil: align leaves by a baseline the host gives them
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.

4 participants