From 807d78b86d60d84c0b6b4fd92ceca839b483ffd9 Mon Sep 17 00:00:00 2001 From: Denis Gomes <6731020+denisg0mes@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:46:54 -0500 Subject: [PATCH] M3: A binding the main layer doesn't have stays an override when instances are relinked Linking imported instances to their mains (and detaching an outer instance, or restoring a main) finds overrides by comparing each layer with its main layer, and compared values only. A layer bound to a variable its main layer doesn't bind, resolving to the main's colour, therefore wasn't an override. The next copy or edit of the main reset it to the main's unbound paint: in a file using a library, a button's icon lost the colour variable the library's button gave it, while the label next to it, whose main binds the variable, kept it. rebase_instance now adds the groups whose bindings differ from the main layer's (diff::rebound_groups), as record_overrides already did for a binding made in an instance. record_overrides no longer clears such an override when an edit sets the value back to the main's (hiding and showing the fill). Bindings are compared by what they bind, so `fill` and `fills/0/color` are one binding. --- crates/engine/src/assets/components.rs | 2 + crates/engine/src/assets/components/diff.rs | 32 ++++++++++++ .../assets/components/nested_binding_tests.rs | 51 +++++++++++++++++++ crates/engine/src/assets/components/patch.rs | 11 ++-- crates/engine/src/assets/components/rebase.rs | 4 +- docs/components-parity.md | 3 +- 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 crates/engine/src/assets/components/nested_binding_tests.rs diff --git a/crates/engine/src/assets/components.rs b/crates/engine/src/assets/components.rs index 06c82563a..80108045d 100644 --- a/crates/engine/src/assets/components.rs +++ b/crates/engine/src/assets/components.rs @@ -338,6 +338,8 @@ pub fn prop_default_value(d: &PropDef) -> Value { } } +#[cfg(test)] +mod nested_binding_tests; #[cfg(test)] mod rebase_source_tests; diff --git a/crates/engine/src/assets/components/diff.rs b/crates/engine/src/assets/components/diff.rs index 5c6b7e4c5..9102a38d6 100644 --- a/crates/engine/src/assets/components/diff.rs +++ b/crates/engine/src/assets/components/diff.rs @@ -35,6 +35,38 @@ pub(super) fn bindings_of<'a>(n: &'a Node, g: &'a str) -> impl Iterator bool { + let canonical = |m: &Node| -> std::collections::BTreeSet<(String, String)> { + bindings_of(m, g) + .map(|(k, v)| { + let key = crate::cmd::lists::list_binding(k).map_or_else(|| k.clone(), |(l, i, f)| format!("{}/{i}/{f}", l.prefix())); + (key, v.clone()) + }) + .collect() + }; + canonical(n) != canonical(src) +} + +/// The property groups whose variable bindings differ between layer `n` and its main layer `src`: +/// overrides even where both resolve to the same value. +pub(super) fn rebound_groups(n: &Node, src: &Node) -> Vec<&'static str> { + let mut compared = Vec::new(); + let mut out = Vec::new(); + for k in n.bound.keys().chain(src.bound.keys()) { + let Some(g) = binding_group(k) else { continue }; + if compared.contains(&g) { + continue; + } + compared.push(g); + if bound_differently(n, src, g) { + out.push(g); + } + } + out +} + /// Property groups that differ between two versions of a node. pub fn diff_groups(a: &Node, b: &Node) -> Vec<&'static str> { let mut out = Vec::new(); diff --git a/crates/engine/src/assets/components/nested_binding_tests.rs b/crates/engine/src/assets/components/nested_binding_tests.rs new file mode 100644 index 000000000..035014dcf --- /dev/null +++ b/crates/engine/src/assets/components/nested_binding_tests.rs @@ -0,0 +1,51 @@ +use serde_json::json; + +use super::rebase_instance; +use super::tests::{button, copy_of, ex, fill, idv, node}; +use crate::{NodeId, Session}; + +fn bound_shape_in_button() -> (Session, NodeId, NodeId, NodeId, NodeId) { + let mut s = Session::new(); + let (_, shape, button, nested) = button(&mut s); + ex(&mut s, "variable.createCollection", json!({"name": "T"})); + ex(&mut s, "variable.create", json!({"collection": "T", "name": "ink", "type": "color", "value": "#111111"})); + let inner = copy_of(&s, nested, shape); + ex(&mut s, "variable.bind", json!({"ids": [inner.0], "field": "fill", "variable": "ink"})); + assert!(node(&s, inner).overrides.contains("fills")); + (s, shape, button, nested, inner) +} + +#[test] +fn relinking_an_instance_keeps_a_binding_its_main_lacks_as_an_override() { + let (mut s, shape, button, nested, inner) = bound_shape_in_button(); + let doc = s.ds_mut().unwrap().doc_mut(); + doc.get_mut(inner).unwrap().overrides.clear(); + rebase_instance(doc, nested); + assert!(node(&s, inner).overrides.contains("fills"), "the same colour from a variable the main doesn't bind"); + ex(&mut s, "node.set", json!({"id": shape, "props": {"fill": "#FF0000"}})); + assert_eq!(fill(&s, inner), "111111", "an edit of the icon's main leaves the bound colour"); + let placed = idv(&ex(&mut s, "instance.create", json!({"component": button, "x": 400, "y": 400}))); + let copy = copy_of(&s, placed, inner); + assert_eq!(node(&s, copy).bound.values().collect::>(), [&node(&s, inner).bound["fill"]]); +} + +#[test] +fn hiding_and_showing_a_bound_fill_keeps_its_override() { + let (mut s, _, _, _, inner) = bound_shape_in_button(); + ex(&mut s, "fill.set", json!({"ids": [inner.0], "index": 0, "visible": false})); + ex(&mut s, "fill.set", json!({"ids": [inner.0], "index": 0, "visible": true})); + let n = node(&s, inner); + assert!(n.bound.contains_key("fill")); + assert!(n.overrides.contains("fills"), "the binding still differs from the main's"); +} + +#[test] +fn a_top_level_instance_s_own_resizing_binding_is_not_an_override() { + let mut s = Session::new(); + let (_, _, button, _) = button(&mut s); + let placed = idv(&ex(&mut s, "instance.create", json!({"component": button, "x": 400, "y": 400}))); + let doc = s.ds_mut().unwrap().doc_mut(); + doc.get_mut(placed).unwrap().bound.insert("minWidth".into(), "VariableID:1:1".into()); + rebase_instance(doc, placed); + assert!(!node(&s, placed).overrides.contains("resizing"), "a top-level instance's resizing is its own"); +} diff --git a/crates/engine/src/assets/components/patch.rs b/crates/engine/src/assets/components/patch.rs index 92d2e2f29..1b275721b 100644 --- a/crates/engine/src/assets/components/patch.rs +++ b/crates/engine/src/assets/components/patch.rs @@ -1,4 +1,4 @@ -use super::diff::{binding_group, bindings_of, diff_groups, follow_boolean_defaults, geometry_derived, variable_groups}; +use super::diff::{binding_group, bound_differently, diff_groups, follow_boolean_defaults, geometry_derived, rebound_groups, variable_groups}; use super::guard::{own_slot_content, relink_copy}; use super::instances::{copy_group, field_group, sync_instance}; use super::sync::insert_linked; @@ -179,12 +179,17 @@ fn override_groups(doc: &Document, before: &Document, id: NodeId, n: &Node, b: & // Binding another variable (or none) where the main binds one is an override. for (k, _) in b.bound.iter().chain(n.bound.iter()) { let Some(g) = binding_group(k) else { continue }; - let rebound = b.bound.get(k) != n.bound.get(k) && !bindings_of(n, g).eq(bindings_of(src, g)); + let rebound = b.bound.get(k) != n.bound.get(k) && bound_differently(n, src, g); if rebound && !groups.contains(&g) { groups.push(g); } } - cleared = raw.iter().filter(|g| !matches!(**g, "size" | "position") && !differs.contains(g) && n.overrides.contains(**g)).copied().collect(); + let rebound = rebound_groups(n, src); + cleared = raw + .iter() + .filter(|g| !matches!(**g, "size" | "position") && !differs.contains(g) && !rebound.contains(g) && n.overrides.contains(**g)) + .copied() + .collect(); if top_root { cleared.retain(|g| !matches!(*g, "component" | "props")); } diff --git a/crates/engine/src/assets/components/rebase.rs b/crates/engine/src/assets/components/rebase.rs index aa782cb20..b8a6c67c7 100644 --- a/crates/engine/src/assets/components/rebase.rs +++ b/crates/engine/src/assets/components/rebase.rs @@ -1,4 +1,4 @@ -use super::diff::{diff_groups, variable_groups}; +use super::diff::{diff_groups, rebound_groups, variable_groups}; use super::instances::{field_group, path_map}; use super::{BTreeMap, BTreeSet, Document, MAX_DEPTH, Node, NodeId, NodeKind, default_instance_name, holds_content}; @@ -216,6 +216,7 @@ pub fn rebase_instance_with(doc: &mut Document, inst: NodeId, mains: &mut MainPa let mut bound: Vec<&str> = m.prop_refs.keys().map(|f| field_group(f)).collect(); bound.extend(variable_groups(n, m)); overrides.extend(value_groups(m, n).into_iter().filter(|g| !bound.contains(&g.as_str()))); + overrides.extend(rebound_groups(n, m).into_iter().map(str::to_string)); if matches!((&m.kind, &n.kind), (NodeKind::Instance { component: a, .. }, NodeKind::Instance { component: b, .. }) if a != b) { overrides.insert("component".into()); } @@ -233,6 +234,7 @@ pub fn rebase_instance_with(doc: &mut Document, inst: NodeId, mains: &mut MainPa let mut groups: Vec = value_groups(m, n) .into_iter() .filter(|g| !matches!(g.as_str(), "name" | "exports" | "interactions") && !from_variables.contains(&g.as_str())) + .chain(rebound_groups(n, m).into_iter().map(str::to_string)) .filter(|g| placed_source.is_some() || !matches!(g.as_str(), "resizing" | "modes")) .collect(); let named = if placed_source.is_some() { n.name != m.name } else { n.name != default_instance_name(doc, component) }; diff --git a/docs/components-parity.md b/docs/components-parity.md index fa4d2494e..2e97e1415 100644 --- a/docs/components-parity.md +++ b/docs/components-parity.md @@ -1,6 +1,6 @@ # Components, variants, styles and variables parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (a style of one library that reaches a file through another library's component is, in a file linking both, the first library's own bound copy, so its modes colour it (#2414); with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); colour variables can be calculated from other colours per mode — `{alpha}` replaces a colour's alpha, `{mix}` blends two — and follow them (#1280); stored variable and collection references keep their identity when another object is named like their id (follow-up to #1542); a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; opening a file contacts no team library server it names until you check it (#1097); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); components can't contain their own instances, directly or through others (#1084); the instance-swap menus have a search field (#1338); an instance-swap property's default menu scrolls (#1338); variables on a text style's fields from the style editor; instance-swap properties in the component playground; duplicating or Alt-dragging a main component makes an instance of it (#892); a bound colour variable's alpha applies once (#802); variables import reads `variables` outside `meta` and warns when it imports none (#790); variant properties reorder by drag; library files saved right after a read are read again; Hide when publishing note corrected; size and resizing overrides of layers inside instances (#731); variables export in the browser as a download; core editor leftovers: component playground, variables inside styles; layers and assets panels behaviour suite and fixes; extended collections tail; styles and variables behaviour suite and fixes; components behaviour suite and fixes; team libraries on the server, library usage and swapping a library; extended collections, variables import/export, gradient stops and variant properties bound to variables) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (a layer inside an instance bound to a variable its main layer doesn't bind keeps that binding as an override when instances are relinked after an import, a detach or a restore, and when its value is set back to the main's, so a library copy or an edit of the main no longer drops it; a style of one library that reaches a file through another library's component is, in a file linking both, the first library's own bound copy, so its modes colour it (#2414); with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); colour variables can be calculated from other colours per mode — `{alpha}` replaces a colour's alpha, `{mix}` blends two — and follow them (#1280); stored variable and collection references keep their identity when another object is named like their id (follow-up to #1542); a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; opening a file contacts no team library server it names until you check it (#1097); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); components can't contain their own instances, directly or through others (#1084); the instance-swap menus have a search field (#1338); an instance-swap property's default menu scrolls (#1338); variables on a text style's fields from the style editor; instance-swap properties in the component playground; duplicating or Alt-dragging a main component makes an instance of it (#892); a bound colour variable's alpha applies once (#802); variables import reads `variables` outside `meta` and warns when it imports none (#790); variant properties reorder by drag; library files saved right after a read are read again; Hide when publishing note corrected; size and resizing overrides of layers inside instances (#731); variables export in the browser as a download; core editor leftovers: component playground, variables inside styles; layers and assets panels behaviour suite and fixes; extended collections tail; styles and variables behaviour suite and fixes; components behaviour suite and fixes; team libraries on the server, library usage and swapping a library; extended collections, variables import/export, gradient stops and variant properties bound to variables) · **Target:** Figma Design (desktop app 126.10.7) Design systems are why teams adopt Figma. **Components: breadth ~96%, ready ~72%. Styles and variables: breadth ~95%, ready ~76% (estimated).** QA'd with a synthetic design system of ~300 @@ -80,6 +80,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`. | Date | Change | Summary | |---|---|---| +| 2026-11-19 | patch | M3: overrides found by comparing a layer with its main (`rebase_instance`: linking instances after a Figma or REST import, detaching an outer instance, restoring a main) counted values only, so a layer bound to a variable the main layer doesn't bind, resolving to the main's colour, wasn't an override; the next copy or edit of the main (a library update reaching another file) reset it to the main's unbound paint. Icons inside buttons of a design system imported from Figma lost their colour variable this way in the files using it. A binding that differs from the main's is now an override there, and an edit that sets the value back to the main's (hiding and showing the fill) no longer clears an override the binding still makes; `fill` and `fills/0/color` count as one binding. Tests: `nested_binding_tests` | | 2026-11-19 | patch | M3, #2414: a kit's style used by a component of a second library reached a file linking both as a second, unbound copy (`::S:1`) frozen in the kit's default mode, so a mode set on the kit's collection didn't colour it (from two hops on, every such style). Publishing now keeps the variables the published styles bind and where the file's copies of other libraries' styles, variables and collections came from; importing files such a copy under that library when the file links it, so it is the file's own bound copy. Test: `library_style_hops_tests::a_kit_style_through_another_library_is_the_kits_bound_copy`; the issue's four-file chain renders Brand and Alt everywhere. Grade unchanged. | | 2026-11-19 | patch | M3, #2349: with one variant of a set selected, the Design panel's variant property dropdowns showed the set's default values, and choosing a value set the default, so the variants swapped places. They now show the selected variant's own values (hover: "This variant's value"), and choosing one renames that variant only; with the set selected they still set its default. Test: `variant_own_value_tests::a_selected_variants_dropdown_shows_and_sets_its_own_value`. Grade unchanged. | | 2026-11-18 | minor | M3, gap 10: library analytics count insertions and detachments of styles and variables. Applying one, or copying or duplicating content that uses it, inserts it; the Detach button detaches it; an instance counts as its component alone. Show usage and `library.usage` give them per style and variable over the chosen period. Modes aren't counted. Numbers unchanged. Tests: `library_asset_counts_tests`, `library_assets_tests`. |