From 2c044f6b80c2bf10340ca6ef36b85694cb72c69a Mon Sep 17 00:00:00 2001 From: Ricardo Date: Thu, 22 Oct 2026 13:16:16 -0600 Subject: [PATCH] .fig export: an override that clears a maximum size writes it as infinite Like an unset axis, a cleared maximum was written as 0 and could collapse the layer (CodeRabbit review on #1152). Co-Authored-By: Claude Opus 5.5 --- crates/format/src/fig/export.rs | 4 +++- crates/format/src/fig/export_tests.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/format/src/fig/export.rs b/crates/format/src/fig/export.rs index c7e64c9f..312aba13 100644 --- a/crates/format/src/fig/export.rs +++ b/crates/format/src/fig/export.rs @@ -2569,7 +2569,9 @@ fn unset(key: &str) -> Option> { "cornerSmoothing" | "stackChildPrimaryGrow" => fl(0.0), "stackMode" => e("NONE"), "stackChildAlignSelf" | "stackPositioning" => e("AUTO"), - "minSize" | "maxSize" => o(vec![("value", xy(0.0, 0.0))]), + "minSize" => o(vec![("value", xy(0.0, 0.0))]), + // No maximum is infinite (a maximum of 0 collapses the layer). + "maxSize" => o(vec![("value", o(vec![("x", Kv::Float(f32::INFINITY)), ("y", Kv::Float(f32::INFINITY))]))]), "gridColumnSpan" | "gridRowSpan" | "maxLines" => int(0), "scrollDirection" => e("NONE"), "scrollBehavior" => e("SCROLLS"), diff --git a/crates/format/src/fig/export_tests.rs b/crates/format/src/fig/export_tests.rs index c7036f03..4ef073b1 100644 --- a/crates/format/src/fig/export_tests.rs +++ b/crates/format/src/fig/export_tests.rs @@ -1319,3 +1319,20 @@ fn set_properties_round_trip() { let NodeKind::Instance { props, .. } = &i.kind else { panic!() }; assert_eq!(props.get("Label"), Some(&Value::String("Hi".into()))); } + +#[test] +fn an_instance_without_its_mains_maximum_size_overrides_it_with_infinity() { + let mut doc = Document::new("File"); + let page = doc.first_page().unwrap(); + let main = doc.create(page, NodeKind::Component { description: String::new(), props: BTreeMap::new() }, "Box", 0.0, 0.0, 100.0, 40.0).unwrap(); + doc.node_mut(main).unwrap().child_layout.max_w = Some(300.0); + doc.create(page, NodeKind::Instance { component: main, props: BTreeMap::new() }, "Box", 0.0, 100.0, 100.0, 40.0).unwrap(); + let (bytes, _) = export(&doc, None).unwrap(); + let archive = Archive::open(&bytes).unwrap(); + let (schema, message) = decode_canvas(&archive.canvas).unwrap(); + let msg = schema.decode_message(schema.find("Message").unwrap(), &message).unwrap(); + let inst = msg.get("nodeChanges").unwrap().list().iter().find(|n| n.get("type").and_then(Kv::str) == Some("INSTANCE")).unwrap(); + let overrides = inst.get("symbolData").unwrap().get("symbolOverrides").unwrap().list(); + let max = overrides.iter().find_map(|o| o.get("maxSize")).unwrap().get("value").unwrap(); + assert_eq!((max.get("x"), max.get("y")), (Some(&Kv::Float(f32::INFINITY)), Some(&Kv::Float(f32::INFINITY)))); +}