Skip to content

fix(slider): make delta calculation idempotent#205

Open
matta wants to merge 1 commit intoDioxusLabs:mainfrom
matta:fix-slider-delta
Open

fix(slider): make delta calculation idempotent#205
matta wants to merge 1 commit intoDioxusLabs:mainfrom
matta:fix-slider-delta

Conversation

@matta
Copy link
Contributor

@matta matta commented Feb 23, 2026

The Slider component tracks dragging via a reactive effect, call it the drag effect. Previously, the delta was read from a global Pointer struct every time the drag effect ran.

The bug: the drag effect was not idempotent, and could run more than once, for reasons outside the Slider's control. It could apply a pointer event's "delta" to the Slider multiple times. Depending on the way the app was written, this could cause the Slider value to deviate far from the what it should be while the user dragged.

This change fixes the bug by shifting the delta calculation inside the drag effect. By introducing a local use_hook to track the last processed position, the effect becomes idempotent with respect to the most recently observed pointer position.

The Slider component tracks dragging via a reactive effect, call it
the drag effect. Previously, the delta was read from a global `Pointer`
struct every time the drag effect ran.

The bug: the drag effect was not idempotent, and could run more than
once, for reasons outside the Slider's control. It could apply a
pointer event's "delta" to the Slider multiple times. Depending on the
way the app was written, this could cause the Slider value to deviate
far from the what it should be while the user dragged.

This change fixes the bug by shifting the delta calculation inside the
drag effect. By introducing a local `use_hook` to track the last
processed position, the effect becomes idempotent with respect to
the most recently observed pointer position.
@github-actions
Copy link

@matta
Copy link
Contributor Author

matta commented Feb 23, 2026

I ran into this bug because my app signals a bunch of state change as sliders move, which I suppose was the cause of the Slider's use_effect being re-run multiple times per pointer event in some cases.

I'm a web-dev and Dioxus noob so I have no claim to this commit being the best way to fix it. The issue is tricky enough that I'm not sure what kind of test hygiene you'd expect as maintainers in this case. I tested the fix against my app and it fixed things nicely. Let me know if I should change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant