Fix number slider value getting stuck tied to mouse position - #4514
Open
Akansh475 wants to merge 1 commit into
Open
Fix number slider value getting stuck tied to mouse position#4514Akansh475 wants to merge 1 commit into
Akansh475 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
frontend/src/components/widgets/inputs/NumberInput.sveltecan let an older pointer-lock completion clear a newer session’s shared abort baseline, potentially producing incorrect number-input delta/abort behavior; make the cleanup conditional on the owning session and clear the shared baseline and delta only when appropriate.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="frontend/src/components/widgets/inputs/NumberInput.svelte">
<violation number="1" location="frontend/src/components/widgets/inputs/NumberInput.svelte:572">
P2: After `localInitialValue` is cleared, this condition is tautologically true, so every pointer-lock completion clears the shared abort baseline, including a newer session's baseline. Clear the shared baseline and delta only when this callback still owns the active drag session.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Comment on lines
+572
to
575
| if (initialValueBeforeDragging === localInitialValue || initialValueBeforeDragging !== undefined) { | ||
| initialValueBeforeDragging = undefined; | ||
| } | ||
| cumulativeDragDelta = 0; |
Contributor
There was a problem hiding this comment.
P2: After localInitialValue is cleared, this condition is tautologically true, so every pointer-lock completion clears the shared abort baseline, including a newer session's baseline. Clear the shared baseline and delta only when this callback still owns the active drag session.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At frontend/src/components/widgets/inputs/NumberInput.svelte, line 572:
<comment>After `localInitialValue` is cleared, this condition is tautologically true, so every pointer-lock completion clears the shared abort baseline, including a newer session's baseline. Clear the shared baseline and delta only when this callback still owns the active drag session.</comment>
<file context>
@@ -491,12 +566,17 @@
+ updateValue(localInitialValue);
+ localInitialValue = undefined;
+ localCumulativeDragDelta = 0;
+ if (initialValueBeforeDragging === localInitialValue || initialValueBeforeDragging !== undefined) {
+ initialValueBeforeDragging = undefined;
+ }
</file context>
Suggested change
| if (initialValueBeforeDragging === localInitialValue || initialValueBeforeDragging !== undefined) { | |
| initialValueBeforeDragging = undefined; | |
| } | |
| cumulativeDragDelta = 0; | |
| if (activeDragCleanup === dragCleanup) { | |
| initialValueBeforeDragging = undefined; | |
| cumulativeDragDelta = 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4231
I dug into this and found the root cause:
document.exitPointerLock()isasync, and the matching
pointerlockchangeevent can fire quite late insome cases. If you release a drag and then quickly start a new one before
that event fires, the old drag's handler was still writing to shared
variables (
initialValueBeforeDragging,cumulativeDragDelta,activeDragCleanup). That's what caused the jump — the stale handler wouldoverwrite the new drag's in-progress value, and in some cases even tear
down the new drag's listeners entirely by clearing the shared cleanup
reference.
The fix moves this state into closures scoped to each individual drag
session, so a late-firing event from an old session can only ever touch
its own data and never interfere with whatever drag is currently active.
Tested by reproducing both scenarios from the issue:
clicking back
Neither causes the jump/stuck behavior anymore after this change.
Probably related to #2807 as well, since that's the same drag code path.