diff --git a/packages/dom/src/auto_update.rs b/packages/dom/src/auto_update.rs index 7060136..a2c8754 100644 --- a/packages/dom/src/auto_update.rs +++ b/packages/dom/src/auto_update.rs @@ -230,6 +230,7 @@ pub fn auto_update( let frame_loop_frame_id = frame_id.clone(); let frame_loop_closure = Rc::new(RefCell::new(None)); let frame_loop_closure_clone = frame_loop_closure.clone(); + let frame_loop_closure_update = update.clone(); *frame_loop_closure_clone.borrow_mut() = Some(Closure::new(move || { let next_ref_rect = get_bounding_client_rect((&owned_reference).into(), false, false, None); @@ -240,7 +241,7 @@ pub fn auto_update( || next_ref_rect.width != prev_ref_rect.width || next_ref_rect.height != prev_ref_rect.height { - update(); + frame_loop_closure_update(); } } @@ -262,6 +263,8 @@ pub fn auto_update( ); } + update(); + Box::new(move || { for ancestor in &ancestors { let event_target: &EventTarget = match ancestor { diff --git a/packages/leptos/tests/visual/src/spec/auto_update.rs b/packages/leptos/tests/visual/src/spec/auto_update.rs index 348cf51..a884b2b 100644 --- a/packages/leptos/tests/visual/src/spec/auto_update.rs +++ b/packages/leptos/tests/visual/src/spec/auto_update.rs @@ -67,6 +67,24 @@ pub fn AutoUpdate() -> impl IntoView { cleanup(); } + let size_factor = match layout_shift() { + LayoutShift::Move => 0.9, + _ => 1.0, + }; + + // Match React test behaviour by moving the size change from style attributes to here. + // The style attributes update after this effect, so `auto_update` would not use the correct size. + _ = reference + .clone() + .style( + "width", + format!("{}px", reference_size() as f64 * size_factor), + ) + .style( + "height", + format!("{}px", reference_size() as f64 * size_factor), + ); + let reference: &Element = &reference; effect_cleanup.replace(Some(auto_update( reference.into(), @@ -96,7 +114,7 @@ pub fn AutoUpdate() -> impl IntoView { view! {
The floating element should update when required.