Repository navigation
Add partial style updates - #26
Merged
Merged
Conversation
There was a problem hiding this comment.
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 publicStyleUpdatetype. - 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TaffyTree.updateStyleand the publicStyleUpdatetypePoint/Size/Rect/Linecomponents while replacing arrays, tagged unions, and complete records as whole valuesImplementation
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
Styleonce, then compares and applies supplied values in one traversal. An unchanged candidate is discarded without dirtying; a changed candidate is validated before oneset_stylecall. This keeps the initial implementation straightforward while respecting Taffy 0.13's immutablestyle()and whole-valueset_style()APIs.Validation
vp run readyvp run check:wasmvp run check:codegenundefinedcoverage for all 41 top-level Style fields