From 981fa0696137d40794665a45e7a8c9b362081083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Torr=C3=B3?= Date: Thu, 19 Nov 2026 11:02:15 +0100 Subject: [PATCH] :bug: Keep fill copies laid out after a component sync in the WebGL render (#13154) * :bug: Keep fill copies laid out after a component sync in the WebGL render Lay out other pages in CLJS and reflow nested layouts that keep their size. Closes #13015 AI-assisted-by: claude-opus-5-5 * :zap: Skip the nested layout pass during WebGL drag previews Gap, padding and margin drags keep the cost they had before the fix. Relates to #13015 AI-assisted-by: claude-opus-5-5 --- .../app/main/data/workspace/shape_layout.cljs | 3 +- .../workspace_layout_other_page_test.cljs | 57 +++++++++ frontend/test/frontend_tests/runner.cljs | 2 + render-wasm/src/shapes/modifiers.rs | 112 ++++++++++++++++++ 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 frontend/test/frontend_tests/data/workspace_layout_other_page_test.cljs diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index 0a5c7b4cfe..6f6cfba59d 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -112,7 +112,8 @@ update-positions-stream (if (d/not-empty? ids) (let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))] - (if (features/active-feature? state "render-wasm/v1") + (if (and (features/active-feature? state "render-wasm/v1") + (= page-id (:current-page-id state))) (rx/of (dwm/apply-wasm-modifiers modif-tree :stack-undo? true :undo-group undo-group diff --git a/frontend/test/frontend_tests/data/workspace_layout_other_page_test.cljs b/frontend/test/frontend_tests/data/workspace_layout_other_page_test.cljs new file mode 100644 index 0000000000..ac0cc0db6f --- /dev/null +++ b/frontend/test/frontend_tests/data/workspace_layout_other_page_test.cljs @@ -0,0 +1,57 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS SUBSIDIARY SL + +(ns frontend-tests.data.workspace-layout-other-page-test + "Regression test for #13015: with render-wasm/v1 active, a `:layout/update` + for a page other than the current one must still lay out its shapes." + (:require + [app.common.test-helpers.compositions :as ctho] + [app.common.test-helpers.files :as cthf] + [app.common.test-helpers.ids-map :as cthi] + [app.common.test-helpers.shapes :as cths] + [app.main.data.workspace.shape-layout :as dwsl] + [cljs.test :as t :include-macros true] + [frontend-tests.helpers.state :as ths] + [frontend-tests.helpers.wasm :as thw])) + +(t/use-fixtures :each + {:before thw/setup-wasm-mocks! + :after thw/teardown-wasm-mocks!}) + +(defn- setup-file + [] + (-> (cthf/sample-file :file1 :page-label :page-a) + (cthf/add-sample-page :page-b) + (ctho/add-frame :board + :x 0 :y 0 :width 500 :height 300 + :layout :flex + :layout-flex-dir :column + :layout-align-items :start + :layout-padding-type :multiple + :layout-padding {:p1 50 :p2 50 :p3 50 :p4 50}) + (cths/add-sample-shape :child + :type :rect + :parent-label :board + :x 50 :y 50 :width 100 :height 20 + :layout-item-h-sizing :fill) + (cthf/switch-to-page :page-a))) + +(t/deftest layout-update-on-another-page-resizes-fill-children + (t/async + done + (let [file (setup-file) + store (ths/setup-store file) + event (#'dwsl/update-layout-positions {:page-id (cthi/id :page-b) + :ids [(cthi/id :board)]})] + (ths/run-store + store done [event] + (fn [new-state] + (let [file' (ths/get-file-from-state new-state) + child (cths/get-shape file' :child :page-label :page-b)] + (t/is (= 400 (:width child)) + "the fill child takes the board width minus its padding") + (t/is (zero? (thw/call-count :propagate-modifiers)) + "WASM only holds the current page, so it must not lay out another one"))))))) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 6c092342c3..3ab76c823c 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -41,6 +41,7 @@ [frontend-tests.data.workspace-context-menu-test] [frontend-tests.data.workspace-focus-test] [frontend-tests.data.workspace-interactions-test] + [frontend-tests.data.workspace-layout-other-page-test] [frontend-tests.data.workspace-libraries-load-test] [frontend-tests.data.workspace-libraries-sync-test] [frontend-tests.data.workspace-mcp-test] @@ -251,6 +252,7 @@ 'frontend-tests.data.workspace-context-menu-test 'frontend-tests.data.workspace-focus-test 'frontend-tests.data.workspace-interactions-test + 'frontend-tests.data.workspace-layout-other-page-test 'frontend-tests.data.workspace-libraries-load-test 'frontend-tests.data.workspace-libraries-sync-test 'frontend-tests.data.workspace-mcp-test diff --git a/render-wasm/src/shapes/modifiers.rs b/render-wasm/src/shapes/modifiers.rs index 1898ed7276..b79d811459 100644 --- a/render-wasm/src/shapes/modifiers.rs +++ b/render-wasm/src/shapes/modifiers.rs @@ -17,6 +17,7 @@ use crate::shapes::{ }; use crate::state::{ShapesPoolRef, State}; use crate::uuid::Uuid; +use crate::{get_render_state, has_render_state}; #[allow(clippy::too_many_arguments)] fn propagate_children( @@ -438,6 +439,22 @@ fn propagate_reflow( } } +fn propagate_nested_reflows( + ids: &[Uuid], + shapes: ShapesPoolRef, + reflown: &HashSet, + entries: &mut VecDeque, +) { + for shape in ids.iter().filter_map(|id| shapes.get(id)) { + for child_id in shape.all_children_iter(shapes, false, false) { + if !reflown.contains(&child_id) && shapes.get(&child_id).is_some_and(Shape::has_layout) + { + entries.push_back(Modifier::reflow(child_id, false)); + } + } + } +} + fn reflow_shape( id: &Uuid, state: &State, @@ -504,6 +521,16 @@ pub fn propagate_modifiers( // are transformed in the same pass. let mut pending_reflows = HashSet::::new(); + let requested_reflows: Vec = entries + .iter() + .filter_map(|modifier| match modifier { + Modifier::Reflow(id, _) => Some(*id), + Modifier::Transform(..) => None, + }) + .collect(); + let interactive = has_render_state() && get_render_state().options.is_interactive_transform(); + let mut nested_layouts_queued = interactive || requested_reflows.is_empty(); + // We first propagate the transforms to the children and then after // recalculate the layouts. The layout can create further transforms that // we need to re-propagate. @@ -564,6 +591,14 @@ pub fn propagate_modifiers( } reflow_shape(id, state, &mut reflown, &mut entries, &mut bounds_temp)?; } + + // A requested reflow also lays out the layouts below it that kept + // their size, so were skipped: a component sync can leave their + // children where the layout would not put them. + if entries.is_empty() && !nested_layouts_queued { + nested_layouts_queued = true; + propagate_nested_reflows(&requested_reflows, shapes, &reflown, &mut entries); + } } Ok(modifiers @@ -927,4 +962,81 @@ mod tests { assert_eq!(bounds.width(), 4.0); assert_eq!(bounds.height(), 4.0); } + + fn add_flex_row(shape: &mut Shape) { + shape.set_shape_type(Type::Frame(Frame::default())); + shape.set_flex_layout_data( + FlexDirection::Row, + 0.0, + 0.0, + AlignItems::Start, + AlignContent::Start, + JustifyItems::Start, + JustifyContent::Start, + WrapType::NoWrap, + 0.0, + 0.0, + 0.0, + 0.0, + ); + } + + fn add_fixed_layout_child(shape: &mut Shape, parent_id: Uuid) { + shape.set_parent(parent_id); + shape.set_flex_layout_child_data( + 0.0, + 0.0, + 0.0, + 0.0, + Sizing::Fix, + Sizing::Fix, + None, + None, + None, + None, + None, + false, + None, + ); + } + + #[test] + fn test_reflow_lays_out_nested_layout_that_keeps_its_size() { + let outer_id = Uuid::new_v4(); + let inner_id = Uuid::new_v4(); + let child_id = Uuid::new_v4(); + + let mut state = State::new(); + state.shapes.initialize(10); + { + let child = state.shapes.add_shape(child_id); + child.set_selrect(100.0, 0.0, 116.0, 16.0); + add_fixed_layout_child(child, inner_id); + + let inner = state.shapes.add_shape(inner_id); + add_flex_row(inner); + add_fixed_layout_child(inner, outer_id); + inner.add_child(child_id); + inner.set_selrect(0.0, 0.0, 300.0, 16.0); + + let outer = state.shapes.add_shape(outer_id); + add_flex_row(outer); + outer.add_child(inner_id); + outer.set_selrect(0.0, 0.0, 300.0, 16.0); + } + + let entry = TransformEntry::from_input(outer_id, Matrix::new_identity()); + let result = propagate_modifiers(&state, &[entry], PixelPrecision::Disabled).unwrap(); + + let transform = result + .iter() + .find(|entry| entry.id == child_id) + .map(|entry| entry.transform) + .expect("the child of the nested layout is laid out"); + + let child = state.shapes.get(&child_id).unwrap(); + let bounds = child.bounds().transform(&transform); + + assert!(is_close_to(bounds.min_x(), 0.0)); + } }