Skip to content

Layout engine polish: sparse-child fix, exhaustive edge tests, invariants docs#63

Merged
RtlZeroMemory merged 7 commits into
mainfrom
layout-engine-polish
Feb 17, 2026
Merged

Layout engine polish: sparse-child fix, exhaustive edge tests, invariants docs#63
RtlZeroMemory merged 7 commits into
mainfrom
layout-engine-polish

Conversation

@RtlZeroMemory

Copy link
Copy Markdown
Owner

Summary

This PR performs a layout-engine polish pass focused on audit hardening and deterministic coverage.

What changed

  • Fixed a real stack measurement crash path when row/column children arrays contain sparse entries (undefined holes).

    • Hardened layout guard helpers against non-VNode inputs.
    • Skipped sparse children in non-constraint stack measure loops.
    • Added regression coverage in layout.edgecases.test.ts.
  • Added exhaustive deterministic layout tests across required audit areas:

    • layout.flex-distribution.test.ts (row/column flex distribution, gaps, min/max, remainder behavior)
    • layout.percentage.test.ts (0%/100%/150%, nested %, cross-axis %, percent+flex ordering)
    • layout.auto-sizing.test.ts (auto sizing interactions with text/box/stack/flex)
    • layout.margin.test.ts (negative margins, root margins, spacing key resolution, margin+padding)
    • layout.aspect-ratio.test.ts (width/height derivation, precedence, min/max, flex context)
    • layout.zero-edge.test.ts (empty stacks, zero-size viewports, empty text, deep nesting, single-child equivalence)
    • layout.stability-signature.test.ts (layout-signature relevance and exclusions)
    • layout.measure-cache.test.ts (cache hit/miss behavior by vnode identity/axis/constraints)
    • layout.hit-test-edge.test.ts (nested clip intersections and boundary semantics)
  • Updated documentation:

    • Added Layout Invariants to docs/guide/layout.md covering coordinate/clamp rules, two-phase measure/layout, flex allocation invariants, percentage resolution order, margin semantics, and aspect-ratio precedence.

Why

  • Prevent crashes on malformed/sparse trees while preserving deterministic validation behavior.
  • Pin existing layout behavior under edge conditions to prevent regressions.
  • Make engine invariants explicit for maintainability and future debugging.

Validation

  • npm run build
  • npm run typecheck
  • node scripts/run-tests.mjs

All passed locally.

Guard stack child constraint probes against non-VNode entries and skip sparse children in non-constraint measure loops. This prevents row/column measurement from throwing when children arrays contain undefined holes and adds a regression case in layout.edgecases.
Add deterministic layout suites for flex distribution, percentage sizing, auto sizing, margin interactions, aspect ratio, zero/empty edges, stability signatures, measure cache behavior, and hit-test clip boundaries.
Document int32/clamping rules, two-phase measure/layout flow, flex allocation invariants, percentage resolution order, margin semantics, and aspect-ratio precedence to match current engine behavior.
Add deterministic cases for single-flex remainder capture, zero-total-flex over-subscription clamps, fractional 0.5/1.5 allocation, and zero-space-after-gap collapse behavior.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dcc4f69271

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/layout/kinds/stack.ts
Use non-empty child counts for stack gap totals, justify start offsets, and justify extra-gap boundary math in row/column layout+measure constraint paths. Add regression coverage for sparse children with justify and with flex/percent constraint passes.
CI/docs/codeql jobs failed before build/test because actions/checkout recursive submodule clone of vendor/zireael could not authenticate in Actions. These workflows do not require submodule materialization to run guardrails/build/tests/docs/codeql, so use non-recursive checkout.
Fix lint failures in CI by formatting newly added layout test suites and normalizing import ordering.
@RtlZeroMemory
RtlZeroMemory merged commit 33dadd6 into main Feb 17, 2026
15 of 17 checks passed
@RtlZeroMemory
RtlZeroMemory deleted the layout-engine-polish branch February 19, 2026 17:45
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