Skip to content

Commit 074dd5f

Browse files
fix: use stable Rust toolchain (#155)
1 parent abf7961 commit 074dd5f

File tree

17 files changed

+329
-283
lines changed

17 files changed

+329
-283
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@v4
2020

2121
- name: Set up Rust toolchain
22-
run: rustup toolchain install nightly --no-self-update --profile default --target wasm32-unknown-unknown
22+
run: rustup toolchain install stable --no-self-update --profile default --target wasm32-unknown-unknown
2323

2424
- name: Set up Rust cache
2525
uses: swatinem/rust-cache@v2
@@ -41,6 +41,7 @@ jobs:
4141
- name: Checkout
4242
uses: actions/checkout@v4
4343

44+
# TODO: Investigate why tests fail on stable toolchain.
4445
- name: Set up Rust toolchain
4546
run: rustup toolchain install nightly --no-self-update --profile default --target wasm32-unknown-unknown
4647

@@ -66,8 +67,9 @@ jobs:
6667
with:
6768
version: 'latest'
6869

70+
# TODO: See comment above about nightly toolchain.
6971
- name: Test
70-
run: cargo test --all-features
72+
run: cargo +nightly test --all-features
7173

7274
- name: Upload visual snapshot diffs
7375
uses: actions/upload-artifact@v4

packages/core/src/compute_position.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,40 +86,42 @@ pub fn compute_position<Element: Clone, Window: Clone>(
8686
middleware_data.set(middleware.name(), new_data);
8787
}
8888

89-
if let Some(reset) = reset
90-
&& reset_count <= 50
91-
{
92-
reset_count += 1;
93-
94-
match reset {
95-
Reset::True => {}
96-
Reset::Value(value) => {
97-
if let Some(reset_placement) = value.placement {
98-
stateful_placement = reset_placement;
99-
}
89+
if let Some(reset) = reset {
90+
if reset_count <= 50 {
91+
reset_count += 1;
92+
93+
match reset {
94+
Reset::True => {}
95+
Reset::Value(value) => {
96+
if let Some(reset_placement) = value.placement {
97+
stateful_placement = reset_placement;
98+
}
10099

101-
if let Some(reset_rects) = value.rects {
102-
rects = match reset_rects {
103-
ResetRects::True => platform.get_element_rects(GetElementRectsArgs {
104-
reference: reference.clone(),
105-
floating,
106-
strategy,
107-
}),
108-
ResetRects::Value(element_rects) => element_rects,
100+
if let Some(reset_rects) = value.rects {
101+
rects = match reset_rects {
102+
ResetRects::True => {
103+
platform.get_element_rects(GetElementRectsArgs {
104+
reference: reference.clone(),
105+
floating,
106+
strategy,
107+
})
108+
}
109+
ResetRects::Value(element_rects) => element_rects,
110+
}
109111
}
110-
}
111112

112-
let Coords {
113-
x: next_x,
114-
y: next_y,
115-
} = compute_coords_from_placement(&rects, stateful_placement, rtl);
116-
x = next_x;
117-
y = next_y;
113+
let Coords {
114+
x: next_x,
115+
y: next_y,
116+
} = compute_coords_from_placement(&rects, stateful_placement, rtl);
117+
x = next_x;
118+
y = next_y;
119+
}
118120
}
119-
}
120121

121-
i = 0;
122-
continue;
122+
i = 0;
123+
continue;
124+
}
123125
}
124126

125127
i += 1;

packages/core/src/middleware/inline.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,21 @@ impl<Element: Clone + PartialEq + 'static, Window: Clone + PartialEq + 'static>
186186

187187
let get_bounding_client_rect = move || {
188188
// There are two rects and they are disjoined.
189-
if client_rects.len() == 2
190-
&& client_rects[0].left > client_rects[1].right
191-
&& let Some(x) = options.x
192-
&& let Some(y) = options.y
193-
{
194-
return client_rects
195-
.clone()
196-
.into_iter()
197-
.find(|rect| {
198-
x > rect.left - padding_object.left
199-
&& x < rect.right + padding_object.right
200-
&& y > rect.top - padding_object.top
201-
&& rect.y < rect.bottom + padding_object.bottom
202-
})
203-
.unwrap_or(fallback.clone());
189+
if client_rects.len() == 2 && client_rects[0].left > client_rects[1].right {
190+
if let Some(x) = options.x {
191+
if let Some(y) = options.y {
192+
return client_rects
193+
.clone()
194+
.into_iter()
195+
.find(|rect| {
196+
x > rect.left - padding_object.left
197+
&& x < rect.right + padding_object.right
198+
&& y > rect.top - padding_object.top
199+
&& rect.y < rect.bottom + padding_object.bottom
200+
})
201+
.unwrap_or(fallback.clone());
202+
}
203+
}
204204
}
205205

206206
// There are 2 or more connected rects.

packages/core/src/middleware/offset.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ fn convert_value_to_coords<Element: Clone, Window: Clone>(
4141
),
4242
};
4343

44-
if let Some(alignment) = alignment
45-
&& let Some(alignment_axis) = alignment_axis
46-
{
47-
cross_axis = match alignment {
48-
Alignment::Start => alignment_axis,
49-
Alignment::End => -alignment_axis,
50-
};
44+
if let Some(alignment) = alignment {
45+
if let Some(alignment_axis) = alignment_axis {
46+
cross_axis = match alignment {
47+
Alignment::Start => alignment_axis,
48+
Alignment::End => -alignment_axis,
49+
};
50+
}
5151
}
5252

5353
if is_vertical {
@@ -192,20 +192,20 @@ impl<Element: Clone + PartialEq, Window: Clone + PartialEq> Middleware<Element,
192192
let diff_coords = convert_value_to_coords(state, &options);
193193

194194
// If the placement is the same and the arrow caused an alignment offset then we don't need to change the positioning coordinates.
195-
if let Some(data_placement) = data.map(|data| data.placement)
196-
&& placement == data_placement
197-
{
198-
let arrow_data: Option<ArrowData> = middleware_data.get_as(ARROW_NAME);
199-
if arrow_data
200-
.and_then(|arrow_data| arrow_data.alignment_offset)
201-
.is_some()
202-
{
203-
return MiddlewareReturn {
204-
x: None,
205-
y: None,
206-
data: None,
207-
reset: None,
208-
};
195+
if let Some(data_placement) = data.map(|data| data.placement) {
196+
if placement == data_placement {
197+
let arrow_data: Option<ArrowData> = middleware_data.get_as(ARROW_NAME);
198+
if arrow_data
199+
.and_then(|arrow_data| arrow_data.alignment_offset)
200+
.is_some()
201+
{
202+
return MiddlewareReturn {
203+
x: None,
204+
y: None,
205+
data: None,
206+
reset: None,
207+
};
208+
}
209209
}
210210
}
211211

packages/core/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub trait Middleware<Element: Clone + 'static, Window: Clone + 'static>: Clone +
277277
/// Middleware with options.
278278
pub trait MiddlewareWithOptions<Element: Clone, Window: Clone, O: Clone> {
279279
/// The options passed to this middleware.
280-
fn options(&self) -> &Derivable<Element, Window, O>;
280+
fn options(&self) -> &Derivable<'_, Element, Window, O>;
281281
}
282282

283283
pub struct Elements<'a, Element: Clone + 'static> {

packages/dioxus/src/use_floating.rs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,29 @@ pub fn use_floating(
6565
});
6666

6767
let update = use_callback(move |_| {
68-
if let Some(reference_element) = reference().map(|reference| reference.as_web_event())
69-
&& let Some(floating_element) = floating().map(|floating| floating.as_web_event())
70-
{
71-
let config = ComputePositionConfig {
72-
placement: Some(placement_option()),
73-
strategy: Some(strategy_option()),
74-
middleware: Some(middleware_option()),
75-
};
76-
77-
let open = open_option();
78-
79-
let position = compute_position((&reference_element).into(), &floating_element, config);
80-
x.set(position.x);
81-
y.set(position.y);
82-
strategy.set(position.strategy);
83-
placement.set(position.placement);
84-
middleware_data.set(position.middleware_data);
85-
// The floating element's position may be recomputed while it's closed
86-
// but still mounted (such as when transitioning out). To ensure
87-
// `is_positioned` will be `false` initially on the next open,
88-
// avoid setting it to `true` when `open === false` (must be specified).
89-
is_positioned.set(open);
68+
if let Some(reference_element) = reference().map(|reference| reference.as_web_event()) {
69+
if let Some(floating_element) = floating().map(|floating| floating.as_web_event()) {
70+
let config = ComputePositionConfig {
71+
placement: Some(placement_option()),
72+
strategy: Some(strategy_option()),
73+
middleware: Some(middleware_option()),
74+
};
75+
76+
let open = open_option();
77+
78+
let position =
79+
compute_position((&reference_element).into(), &floating_element, config);
80+
x.set(position.x);
81+
y.set(position.y);
82+
strategy.set(position.strategy);
83+
placement.set(position.placement);
84+
middleware_data.set(position.middleware_data);
85+
// The floating element's position may be recomputed while it's closed
86+
// but still mounted (such as when transitioning out). To ensure
87+
// `is_positioned` will be `false` initially on the next open,
88+
// avoid setting it to `true` when `open === false` (must be specified).
89+
is_positioned.set(open);
90+
}
9091
}
9192
});
9293

@@ -108,16 +109,18 @@ pub fn use_floating(
108109
cleanup.call(());
109110

110111
if let Some(while_elements_mounted) = &while_elements_mounted_option {
111-
if let Some(reference_element) = reference().map(|reference| reference.as_web_event())
112-
&& let Some(floating_element) = floating().map(|floating| floating.as_web_event())
113-
{
114-
while_elements_mounted_cleanup.replace(Some(Rc::new((*while_elements_mounted)(
115-
(&reference_element).into(),
116-
&floating_element,
117-
Rc::new(move || {
118-
update.call(());
119-
}),
120-
))));
112+
if let Some(reference_element) = reference().map(|reference| reference.as_web_event()) {
113+
if let Some(floating_element) = floating().map(|floating| floating.as_web_event()) {
114+
while_elements_mounted_cleanup.replace(Some(Rc::new(
115+
(*while_elements_mounted)(
116+
(&reference_element).into(),
117+
&floating_element,
118+
Rc::new(move || {
119+
update.call(());
120+
}),
121+
),
122+
)));
123+
}
121124
}
122125
} else {
123126
update.call(());

packages/dom/src/auto_update.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,18 @@ pub fn auto_update(
346346
let update = update.clone();
347347

348348
move |entries: Vec<ResizeObserverEntry>| {
349-
if let Some(first_entry) = entries.first()
350-
&& resize_reference_element
349+
if let Some(first_entry) = entries.first() {
350+
if resize_reference_element
351351
.as_ref()
352352
.is_some_and(|reference_element| first_entry.target() == *reference_element)
353-
{
354-
if let Some(reobserve_frame) = reobserve_frame.take() {
355-
cancel_animation_frame(reobserve_frame);
356-
}
353+
{
354+
if let Some(reobserve_frame) = reobserve_frame.take() {
355+
cancel_animation_frame(reobserve_frame);
356+
}
357357

358-
reobserve_frame
359-
.replace(Some(request_animation_frame(reobserve_closure.as_ref())));
358+
reobserve_frame
359+
.replace(Some(request_animation_frame(reobserve_closure.as_ref())));
360+
}
360361
}
361362

362363
update();
@@ -368,14 +369,14 @@ pub fn auto_update(
368369
.expect("Resize observer should be created."),
369370
));
370371

371-
if let Some(reference) = reference_element.as_ref()
372-
&& !animation_frame
373-
{
374-
resize_observer
375-
.borrow()
376-
.as_ref()
377-
.expect("Resize observer should exist.")
378-
.observe(reference);
372+
if let Some(reference) = reference_element.as_ref() {
373+
if !animation_frame {
374+
resize_observer
375+
.borrow()
376+
.as_ref()
377+
.expect("Resize observer should exist.")
378+
.observe(reference);
379+
}
379380
}
380381

381382
resize_observer
@@ -405,10 +406,10 @@ pub fn auto_update(
405406
let next_ref_rect =
406407
get_bounding_client_rect((&owned_reference).into(), false, false, None);
407408

408-
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref()
409-
&& !rects_are_equal(prev_ref_rect, &next_ref_rect)
410-
{
411-
update();
409+
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref() {
410+
if !rects_are_equal(prev_ref_rect, &next_ref_rect) {
411+
update();
412+
}
412413
}
413414

414415
prev_ref_rect.replace(Some(next_ref_rect));
@@ -426,13 +427,14 @@ pub fn auto_update(
426427

427428
let next_ref_rect = get_bounding_client_rect((&owned_reference).into(), false, false, None);
428429

429-
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref()
430-
&& (next_ref_rect.x != prev_ref_rect.x
430+
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref() {
431+
if next_ref_rect.x != prev_ref_rect.x
431432
|| next_ref_rect.y != prev_ref_rect.y
432433
|| next_ref_rect.width != prev_ref_rect.width
433-
|| next_ref_rect.height != prev_ref_rect.height)
434-
{
435-
update();
434+
|| next_ref_rect.height != prev_ref_rect.height
435+
{
436+
update();
437+
}
436438
}
437439

438440
prev_ref_rect.replace(Some(next_ref_rect));

packages/dom/src/platform/convert_offset_parent_relative_rect_to_viewport_relative_rect.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ pub fn convert_offset_parent_relative_rect_to_viewport_relative_rect(
5353

5454
#[allow(clippy::nonminimal_bool)]
5555
if is_offset_parent_an_element || (!is_offset_parent_an_element && !is_fixed) {
56-
if let Some(offset_parent) = offset_parent.as_ref()
57-
&& (get_node_name(offset_parent.into()) != "body"
58-
|| is_overflow_element(&document_element))
59-
{
60-
scroll = get_node_scroll(offset_parent.into());
56+
if let Some(offset_parent) = offset_parent.as_ref() {
57+
if get_node_name(offset_parent.into()) != "body"
58+
|| is_overflow_element(&document_element)
59+
{
60+
scroll = get_node_scroll(offset_parent.into());
61+
}
6162
}
6263

6364
if let Some(ElementOrWindow::Element(offset_parent)) = offset_parent {

0 commit comments

Comments
 (0)