Skip to content

Commit

Permalink
Fix auto update visual test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Apr 6, 2024
1 parent fc5651d commit 74de5f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/dom/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}

Expand All @@ -262,6 +263,8 @@ pub fn auto_update(
);
}

update();

Box::new(move || {
for ancestor in &ancestors {
let event_target: &EventTarget = match ancestor {
Expand Down
20 changes: 19 additions & 1 deletion packages/leptos/tests/visual/src/spec/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -96,7 +114,7 @@ pub fn AutoUpdate() -> impl IntoView {

view! {
<h1>AutoUpdate</h1>
<Show when=move || layout_shift() == LayoutShift::Delete>
<Show when=move || layout_shift() != LayoutShift::Delete>
<p>The floating element should update when required.</p>
</Show>
<Show when=move || layout_shift() == LayoutShift::Insert>
Expand Down

0 comments on commit 74de5f8

Please sign in to comment.