From 24c6281644e849c742358add9c2ceb9ecaefaa11 Mon Sep 17 00:00:00 2001 From: Adam Gerhant <116332429+adamgerhant@users.noreply.github.com> Date: Sun, 6 Jul 2025 14:34:43 -0700 Subject: [PATCH] Fix regression with migration code changed in node UI wire refactor (#2840) Fixes --- .../document/graph_operation/utility_types.rs | 7 +++++++ .../document/utility_types/network_interface.rs | 13 ++++++++++++- .../src/messages/portfolio/document_migration.rs | 15 +++++++-------- .../portfolio/portfolio_message_handler.rs | 1 + 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/editor/src/messages/portfolio/document/graph_operation/utility_types.rs b/editor/src/messages/portfolio/document/graph_operation/utility_types.rs index 311e22aaa..216dc8bf2 100644 --- a/editor/src/messages/portfolio/document/graph_operation/utility_types.rs +++ b/editor/src/messages/portfolio/document/graph_operation/utility_types.rs @@ -97,6 +97,8 @@ impl<'a> ModifyInputsContext<'a> { }; } + let layer_input_connector = post_node_input_connector.clone(); + // Sink post_node down to the end of the non layer chain that feeds into post_node, such that pre_node is the layer node at insert_index + 1, or None if insert_index is the last layer loop { let pre_node_output_connector = network_interface.upstream_output_connector(&post_node_input_connector, &[]); @@ -105,6 +107,11 @@ impl<'a> ModifyInputsContext<'a> { Some(OutputConnector::Node { node_id: pre_node_id, .. }) if !network_interface.is_layer(&pre_node_id, &[]) => { // Update post_node_input_connector for the next iteration post_node_input_connector = InputConnector::node(pre_node_id, 0); + // Insert directly under layer if moving to the end of a layer stack that ends with a non layer node that does not have an exposed primary input + let primary_is_exposed = network_interface.input_from_connector(&post_node_input_connector, &[]).is_some_and(|input| input.is_exposed()); + if !primary_is_exposed { + return layer_input_connector; + } } _ => break, // Break if pre_node_output_connector is None or if pre_node_id is a layer } diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface.rs b/editor/src/messages/portfolio/document/utility_types/network_interface.rs index 65e58693f..c4255120a 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface.rs @@ -4093,6 +4093,18 @@ impl NodeNetworkInterface { } } + // When opening an old document to ensure the output names match the number of exports + pub fn validate_output_names(&mut self, node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId]) { + if let DocumentNodeImplementation::Network(network) = &node.implementation { + let number_of_exports = network.exports.len(); + let Some(metadata) = self.node_metadata_mut(node_id, network_path) else { + log::error!("Could not get metadata for node: {:?}", node_id); + return; + }; + metadata.persistent_metadata.output_names.resize(number_of_exports, "".to_string()); + } + } + /// Keep metadata in sync with the new implementation if this is used by anything other than the upgrade scripts pub fn replace_reference_name(&mut self, node_id: &NodeId, network_path: &[NodeId], reference_name: String) { let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else { @@ -5639,7 +5651,6 @@ impl NodeNetworkInterface { self.unload_all_nodes_bounding_box(network_path); } - // TODO: Run the auto layout system to make space for the new nodes /// Disconnect the layers primary output and the input to the last non layer node feeding into it through primary flow, reconnects, then moves the layer to the new layer and stack index pub fn move_layer_to_stack(&mut self, layer: LayerNodeIdentifier, mut parent: LayerNodeIdentifier, mut insert_index: usize, network_path: &[NodeId]) { // Prevent moving an artboard anywhere but to the ROOT_PARENT child stack diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index 0d42f30f8..20ce8ea8e 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -614,16 +614,15 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_ // Make the "Quantity" parameter a u32 instead of f64 if reference == "Sample Polyline" { - let node_definition = resolve_document_node_type("Sample Polyline").unwrap(); - let mut new_node_template = node_definition.default_node_template(); - // Get the inputs, obtain the quantity value, and put the inputs back - let old_inputs = document.network_interface.replace_inputs(node_id, network_path, &mut new_node_template).unwrap(); - let quantity_value = old_inputs.get(3).cloned(); + let quantity_value = document + .network_interface + .input_from_connector(&InputConnector::Node { node_id: *node_id, input_index: 3 }, network_path) + .unwrap(); - if let Some(NodeInput::Value { tagged_value, exposed }) = quantity_value { - if let TaggedValue::F64(value) = *tagged_value { - let new_quantity_value = NodeInput::value(TaggedValue::U32(value as u32), exposed); + if let NodeInput::Value { tagged_value, exposed } = quantity_value { + if let TaggedValue::F64(value) = **tagged_value { + let new_quantity_value = NodeInput::value(TaggedValue::U32(value as u32), *exposed); document.network_interface.set_input(&InputConnector::node(*node_id, 3), new_quantity_value, network_path); } } diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 35a1eb516..a6d9da338 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -431,6 +431,7 @@ impl MessageHandler> for PortfolioMes for (node_id, node, path) in document.network_interface.document_network().clone().recursive_nodes() { document.network_interface.validate_input_metadata(node_id, node, &path); document.network_interface.validate_display_name_metadata(node_id, &path); + document.network_interface.validate_output_names(node_id, node, &path); } // Ensure layers are positioned as stacks if they are upstream siblings of another layer