Skip to content

Add partial style updates - #26

Merged
hyfdev merged 5 commits into
mainfrom
agent/style-update-implementation
Aug 16, 2026
Merged

hyfdev merged 5 commits into
mainfrom
agent/style-update-implementation

Conversation

@hyfdev

@hyfdev hyfdev commented Aug 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add TaffyTree.updateStyle and the public StyleUpdate type
  • preserve omitted fields and omitted Point / Size / Rect / Line components while replacing arrays, tagged unions, and complete records as whole values
  • keep invalid updates atomic and avoid dirtying nodes for empty or unchanged updates
  • document the API and cover the shared Node and Wasm behavior

Implementation

Style updates are converted into an owned Rust patch with field and geometry-component presence masks before tree access. An empty patch returns immediately. For a nonempty patch, the binding clones the stored Style once, then compares and applies supplied values in one traversal. An unchanged candidate is discarded without dirtying; a changed candidate is validated before one set_style call. This keeps the initial implementation straightforward while respecting Taffy 0.13's immutable style() and whole-value set_style() APIs.

Validation

  • vp run ready
  • vp run check:wasm
  • vp run check:codegen
  • exhaustive changed, equal, and explicit-undefined coverage for all 41 top-level Style fields
  • independent adversarial reviews of correctness and safety, plus over-design and simplicity; targeted re-review after simplification passed

@hyfdev
hyfdev marked this pull request as ready for review August 16, 2026 12:54
Copilot AI lite review requested due to automatic review settings August 16, 2026 12:54
@hyfdev
hyfdev merged commit 9c7139c into main Aug 16, 2026
6 checks passed

Copilot AI 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.

Pull request overview

Adds an additive style update API to the Node binding (TaffyTree.updateStyle) that can patch only supplied style fields/components while preserving omitted/undefined values, keeping updates atomic (validate-before-write) and avoiding dirtying nodes for no-op updates.

Changes:

  • Introduces TaffyTree.updateStyle(node, update) and exports the public StyleUpdate type.
  • Implements Rust-side patch parsing with presence masks, merge-apply, equality checks (including float bit-pattern comparisons), and validate-before-single-write semantics.
  • Adds comprehensive Node tests + TypeScript declaration tests, and updates website/docs + internal decision records to document the new contract.

Reviewed changes

Copilot reviewed 20 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/taffyjs-node/tests/types/style.test-d.ts Adds StyleUpdate typing assertions and updateStyle usage/negative cases.
tests/taffyjs-node/tests/types/public-api.test-d.ts Verifies public API surface includes StyleUpdate and updateStyle.
tests/taffyjs-node/tests/tree/update-style.test.mts New integration test suite covering update semantics, atomicity, dirtying rules, and invalid node IDs.
tests/taffyjs-node/tests/tree/fixtures/measure-reentrancy.ts Includes updateStyle in reentrancy/busy-tree operation list.
tests/taffyjs-node/tests/tree/compute-layout-with-measure.test.mts Updates expected busy-operation count after adding updateStyle.
packages/taffyjs-node/src/tree.ts Adds the TaffyTree.updateStyle wrapper calling into the binding.
packages/taffyjs-node/src/public-types.ts Exports StyleUpdate and adjusts StyleInput docs to distinguish replacement vs update semantics.
packages/taffyjs-node/src/index.ts Re-exports StyleUpdate from the package entrypoint.
packages/taffyjs-node/index.js Emits the runtime updateStyle method in the built JS bundle.
packages/taffyjs-node/index.d.ts Updates generated declarations for StyleUpdate and updateStyle.
packages/taffyjs-node/binding.d.ts Adds rawUpdateStyle to the binding type surface.
crates/taffyjs_binding/src/style.rs Implements patch presence masks, patch application/merge, and merged-style validation for atomic updates.
crates/taffyjs_binding/src/lib.rs Exposes rawUpdateStyle and wires it to Rust patch/apply/validate + set_style.
crates/taffyjs_binding/src/geometry.rs Returns both value and component-presence masks for partial geometry inputs.
apps/website/node/styles-and-context.md Documents updateStyle behavior and contrasts it with setStyle.
apps/website/node/style.md Updates style reference text to include StyleUpdate and update semantics.
apps/website/node/index.md Updates docs index links to mention partial updates.
apps/website/node/errors.md Updates error docs to include update-style input validation behavior.
apps/website/guide/styles-and-values.md Adds guide section explaining updateStyle preservation/whole-replacement rules.
.agents/docs/taffyjs-node-decisions.md Records and vouches the “Partial style updates” API decision.
.agents/docs/binding-mapping.md Documents update semantics and Rust patch strategy in binding mapping notes.
.agents/docs/binding-cases.md Extends binding cases docs with additive partial update semantics and implementation notes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +950 to 960
pub(crate) fn apply_patch(current: &Style, patch: StylePatch) -> BindingResult<Option<Style>> {
if patch.is_empty() {
return Ok(None);
}
let mut updated = current.clone();
if !patch.apply(&mut updated) {
return Ok(None);
}
validate(&updated)?;
Ok(Some(updated))
}
hyfdev added a commit that referenced this pull request Aug 16, 2026
hyfdev added a commit that referenced this pull request Aug 16, 2026
Add partial native style updates and the Yoga-compatible package backed by WebAssembly.

Refs: #26, #27, #29
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.

2 participants