🐛 Keep fill copies laid out after a component sync in the WebGL render (#13154)

* 🐛 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

* ⚡ 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
This commit is contained in:
Elena Torró 2026-11-19 11:02:15 +01:00 committed by GitHub
parent b6db09e2fb
commit 981fa06961
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 173 additions and 1 deletions

View File

@ -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

View File

@ -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")))))))

View File

@ -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

View File

@ -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<Uuid>,
entries: &mut VecDeque<Modifier>,
) {
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::<Uuid>::new();
let requested_reflows: Vec<Uuid> = 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));
}
}