Skip to content

Fix slider interference with scroll gestures on touch devices across all diagrams#82

Merged
lookbusy1344 merged 10 commits intomainfrom
copilot/fix-twins-paradox-scrolling-issue
Dec 21, 2025
Merged

Fix slider interference with scroll gestures on touch devices across all diagrams#82
lookbusy1344 merged 10 commits intomainfrom
copilot/fix-twins-paradox-scrolling-issue

Conversation

Copy link
Contributor

Copilot AI commented Dec 20, 2025

On touch devices, scrolling the page caused D3-created sliders in Minkowski diagrams to briefly trigger, shifting rendered values before snapping back to correct values.

Root Cause

D3-created sliders in multiple diagrams captured touch events during vertical scrolling, generating spurious input events.

Affected Components Fixed

Twins Paradox Tab (minkowski-twins.ts)

  • Velocity slider

Spacetime Interval Tab (minkowski.ts)

  • Position slider (animation control)

Simultaneity Diagram (simultaneity.ts)

  • Velocity slider
  • Position slider

Changes

Touch Event Filtering

  • Track touch interaction state and initial position
  • Analyze gesture direction before deciding handling
  • Only call preventDefault() for horizontal gestures (slider interaction)
  • Allow vertical gestures (scrolling) to pass through normally
.on("touchmove", function (event: TouchEvent) {
  const deltaX = Math.abs(touch.clientX - startX);
  const deltaY = Math.abs(touch.clientY - startY);
  
  if (deltaX > MIN_GESTURE_THRESHOLD || deltaY > MIN_GESTURE_THRESHOLD) {
    if (deltaY > deltaX) {
      // Vertical gesture - allow scroll
      isSliderActive = false;
      return;
    }
    // Horizontal gesture - use slider
    event.preventDefault();
  }
})

CSS Properties

  • touch-action: pan-y on slider containers (allows vertical scrolling)
  • touch-action: none on slider inputs (enables custom gesture handling)

Safety

  • Added null checks for TouchEvent.touches edge cases
  • Extract gesture threshold constant (10px minimum movement)

Testing

  • ✅ All 411 tests pass
  • ✅ Build succeeds without errors
  • ✅ TypeScript compilation successful
  • ✅ Security scan shows no vulnerabilities
Original prompt

This section details on the original issue you should resolve

<issue_title>Twins paradox scrolling issue</issue_title>
<issue_description>In the Javascript calculator, on the twins paradox tab Minkowski diagram, when scrolling the page the velocity rendered seems to shift before quickly snapping back to the correct value. This happens on touch devices like iPad.

It seems to briefly switch to the default 0.8c</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 20, 2025
Copilot AI and others added 6 commits December 20, 2025 21:32
Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
…fying

Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix twins paradox scrolling issue in calculator Fix velocity slider interference with scroll gestures on touch devices Dec 20, 2025
Copilot AI requested a review from lookbusy1344 December 20, 2025 21:44
@lookbusy1344
Copy link
Owner

@copilot if this is the correct diagnosis of the problem, why does it go back to the proper velocity setting after a moment?

Copy link
Contributor Author

Copilot AI commented Dec 20, 2025

@copilot if this is the correct diagnosis of the problem, why does it go back to the proper velocity setting after a moment?

Great question! The "snap back" happens because of the feedback loop between the slider and the diagram controller.

What was happening:

  1. During scroll, the slider generated a spurious input event (e.g., reading default 0.8c)
  2. The display updated immediately, showing the wrong velocity
  3. After 300ms debounce, the onVelocityChange callback fired, triggering a full recalculation
  4. The controller's update() method then corrected the slider value back to the proper velocity (lines 1052-1056 in minkowski-twins.ts)

So the "snap back" was the controller resetting the slider to the correct value after the spurious input event had already updated the display. The fix prevents the spurious input events from firing during scrolling, eliminating both the initial shift and the snap back.

Fixed in commit ae3bdd1.

@lookbusy1344
Copy link
Owner

@copilot does this bug affect other tabs, like the spacetime interval tab. If so fix it

… diagram sliders

Co-authored-by: lookbusy1344 <3680611+lookbusy1344@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 20, 2025

@copilot does this bug affect other tabs, like the spacetime interval tab. If so fix it

Yes, the bug affected other tabs with D3-created sliders. Fixed all affected sliders:

Spacetime Interval tab - Position slider (animation control)
Simultaneity diagram - Velocity and position sliders

Applied the same touch event handling to all three diagrams. All sliders now properly distinguish between vertical scrolling and horizontal slider interaction.

Fixed in commit 9211b0b.

Copilot AI changed the title Fix velocity slider interference with scroll gestures on touch devices Fix slider interference with scroll gestures on touch devices across all diagrams Dec 20, 2025
lookbusy1344 and others added 2 commits December 21, 2025 09:51
…gging

Extract duplicated touch gesture detection logic from three diagram files
into minkowski-core.ts, creating attachSliderTouchHandlers() utility
function. This eliminates ~160 lines of duplication and provides a single
source of truth for distinguishing scroll from slider gestures.

Add comprehensive error logging for production debugging:
- console.error when TouchEvent.touches is null/undefined (browser bugs)
- console.warn when touch data is lost mid-gesture (system interruptions)
- console.debug when gestures are cancelled (OS events like calls)

All logging includes browser UserAgent for device-specific debugging,
making it possible to diagnose "doesn't work on my iPad" issues with
actionable data instead of guesswork.

Net impact: -69 lines, improved maintainability, production-ready error
visibility.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add 22 new tests for touch gesture detection covering all critical gaps
identified in code review:

Gesture Direction Detection (6 tests):
- Horizontal swipes trigger slider interaction (preventDefault)
- Vertical swipes allow page scrolling (no preventDefault)
- Movement below 10px threshold doesn't trigger gesture classification
- Threshold boundary testing (9px ignored, 11px detected)
- Diagonal movement uses dominant axis for classification

Null Safety (4 tests):
- Null TouchEvent.touches logs error and fails safely
- Empty touches array logs error
- Touch data loss mid-gesture logs warning and deactivates
- Inactive sliders ignore spurious touchmove events

State Management (6 tests):
- Touch lifecycle (touchstart/touchmove/touchend/touchcancel)
- Start coordinate capture for delta calculations
- Rapid touch cycles handled correctly
- Independent state across multiple sliders

Integration (3 tests):
- CSS touch-action property verification
- D3 selection method chaining
- Event handler composition

All tests use realistic mock TouchEvent objects and verify both behavior
and logging output. Covers the core bug fix logic that distinguishes
scroll from slider gestures on touch devices.

Test count: 433 total (up from 411)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@lookbusy1344 lookbusy1344 marked this pull request as ready for review December 21, 2025 09:56
@lookbusy1344 lookbusy1344 merged commit 47a697e into main Dec 21, 2025
6 checks passed
@lookbusy1344 lookbusy1344 deleted the copilot/fix-twins-paradox-scrolling-issue branch December 21, 2025 09:56
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.

Twins paradox scrolling issue

2 participants