Skip to content

feat(core): upgrade mjolnir.js for DoubleClickDrag recognizer - #10416

Merged
chrisgervang merged 7 commits into
masterfrom
x/mjolnir-up
Jul 10, 2026
Merged

chrisgervang merged 7 commits into
masterfrom
x/mjolnir-up

Conversation

@Pessimistress

@Pessimistress Pessimistress commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Upgrades mjolnir.js to v3.0.1 and replaces the controller's hand-rolled pointer/tap logic for double-click-drag zoom with mjolnir's DoubleClickDrag recognizer. Also fixes a bug where runtime controller prop changes via deck.setProps() had no effect.

Changes

mjolnir.js upgrade

  • Upgrade to ^3.0.1 which provides the DoubleClickDrag recognizer
  • Remove raw gesture handling from Controller class, use the new recognizer events (dblclickdragstart, dblclickdragmove, dblclickdragend)

Recognizer wiring (constants.ts)

  • Register dblclick and dblclickdrag recognizers disabled by default (enable: false)
  • Add dblclickdrag to click's requireFailure list (prevents spurious clicks before drag-zoom)
  • Document registration order (recognizeWith/requireFailure resolve by name)

Click latency fix (deck.ts)

  • Use watch() (passive) for dblclick in Deck's picking registration so the picking system doesn't force-enable the recognizer
  • Clone the view in _getViews() instead of mutating props in-place, fixing runtime controller prop propagation

Controller defaults (controller.ts)

  • doubleClickDragZoom defaults to false (new feature, opt-in)
  • doubleClickZoom remains true (existing behavior preserved)
  • Enabling either adds ~300ms latency to click events (documented)

Tests

  • Integration tests for dblclick zoom in/out, click delay measurement, and runtime prop toggle regression
  • Unit tests for controller gesture config
  • Interactive test/apps/gesture-timing app for measuring event delays

Latency tradeoff

When doubleClickZoom or doubleClickDragZoom is enabled, the click recognizer's requireFailure dependency forces a ~300ms wait before emitting click (to rule out double-click). Setting controller: {doubleClickZoom: false} gives immediate clicks. This also disables onClick(tapCount=2) for double-click picking (PR #9629).

Test plan

  • All 13 integration tests pass (pan, rotate, dblclick zoom, keyboard, click delay, runtime toggle)
  • All 36 controller unit tests pass
  • All 542 core module tests pass
  • Runtime toggle regression: red without fix, green with fix
  • RECOGNIZERS ordering confirmed: swapping causes runtime error
  • Gesture timing app demonstrates ~300ms vs ~0ms click delay

How to test

cd test/apps/gesture-timing && npm run start-local

Click the map → observe event log. Toggle doubleClickZoom or use preset buttons to see click latency change in real-time.


Generated with Claude Code


Note

Medium Risk
Touches core viewport gesture recognition and changes default double-click-drag behavior; mis-wired recognizers or the view-clone fix could affect click timing and controller updates at runtime.

Overview
Upgrades mjolnir.js to ^3.0.1 and moves double-click-drag zoom out of hand-rolled pointer* handling in Controller into mjolnir’s DoubleClickDrag events (dblclickdragstart / move / end / cancel), using event.scale for zoom.

Recognizer setup in constants.ts registers dblclick and dblclickdrag disabled by default, wires click to requireFailure on those recognizers, and documents registration order. doubleClickDragZoom now defaults to false in setProps (opt-in). Docs call out the ~300ms single-click delay when doubleClickZoom or doubleClickDragZoom is on, and that turning off doubleClickZoom drops onClick with tapCount: 2.

Deck registers dblclick via watch() for picking so the picking path doesn’t always enable the double-click recognizer, and _getViews() clones the view when applying the legacy controller prop so runtime deck.setProps({ controller }) updates actually propagate.

Adds integration/unit coverage for click delay and runtime toggles, plus a test/apps/gesture-timing dev app to visualize latency.

Reviewed by Cursor Bugbot for commit 551130d. Bugbot is set up for automated code reviews on this repo. Configure here.

@coveralls

coveralls commented Jul 3, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 83.165% (+0.03%) from 83.138% — x/mjolnir-up into master

@chrisgervang chrisgervang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup!

@chrisgervang

chrisgervang commented Jul 4, 2026 •

Copy link
Copy Markdown
Collaborator

The dblclickdrag recognizer is not in the click recognizer's requireFailure list, so it does not contribute to click delay being discussed in #10388. But, should it be included for the same reason dblclick is in the list?

click: [Tap, {event: 'click'}, null, ['dblclick', 'dblclickdrag']]

I think it should be in the list to avoid spurious clicks, and then if we agree on prioritizing responsiveness, I'd consider disabling it by default along the same lines as #10422.

chrisgervang added a commit that referenced this pull request Jul 4, 2026
Same principle — once #10416 lands, dblclickdrag should be in click's
requireFailure list to prevent spurious clicks before a drag-zoom.
That would reintroduce the 300ms delay, so disable by default too.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread modules/core/src/lib/constants.ts Resolved
chrisgervang added a commit that referenced this pull request Jul 4, 2026
Same principle — once #10416 lands, dblclickdrag should be in click's
requireFailure list to prevent spurious clicks before a drag-zoom.
That would reintroduce the 300ms delay, so disable by default too.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
chrisgervang and others added 3 commits July 10, 2026 10:32
…p changes (#10422)

* fix(core): disable doubleClickZoom by default to eliminate 300ms click delay

The click recognizer's requireFailure dependency on dblclick causes
mjolnir.js to defer click events by 300ms. Disabling doubleClickZoom
by default removes this delay while keeping doubleClickDragZoom
available for zoom-by-drag gestures.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(core): also disable doubleClickDragZoom by default

Same principle — once #10416 lands, dblclickdrag should be in click's
requireFailure list to prevent spurious clicks before a drag-zoom.
That would reintroduce the 300ms delay, so disable by default too.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(core): add dblclickdrag to click's requireFailure list

Prevents spurious click events from firing before a double-click-drag
zoom gesture is recognized. Without this, a click would emit on the
first tap before the recognizer determines the user intends to drag.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* test(core): add click delay unit tests for controller gesture config

Tests verify through the full EventManager → recognizer pipeline that:
- Click fires immediately when doubleClickZoom and doubleClickDragZoom
  are both disabled (the new default)
- Click is delayed ~300ms when doubleClickZoom is enabled
- Click is delayed ~300ms when doubleClickDragZoom is enabled

Also reorders RECOGNIZERS so dblclickdrag is registered before click,
which is required for click's requireFailure reference to resolve.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(core): ensure dblclick recognizer is disabled when doubleClickZoom is false

The dblclick/dblclickdrag recognizers start with enable:false so they don't
cause the 300ms click delay out of the box. Deck's picking system uses watch()
(passive) for the dblclick event so it doesn't force-enable the recognizer.
Only the controller's doubleClickZoom option enables it.

Also adds integration tests that verify click latency at the Deck level using
real pointer events dispatched to the canvas.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* test(core): fix dblclick integration tests using direct pointer dispatch

The dblclick tests were broken because page.mouse.dblclick() doesn't
properly target the canvas inside vitest's browser iframe. Fixed by
dispatching PointerEvents directly on the canvas element, matching how
mjolnir's PointerEventInput listener works (pointerdown on element,
pointerup on window). Each test uses a fresh Deck instance for isolation.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(core): propagate runtime controller prop changes to ViewManager

Deck._getViews() was mutating the View instance's props.controller in-place,
so ViewManager._diffViews short-circuited on identity (same object) and never
triggered _rebuildViewports. Controller option changes via setProps had no
effect at runtime. Fixed by cloning the view when applying the controller prop.

Also adds a gesture-timing test app that measures event handling delays and
demonstrates the ~300ms click latency tradeoff with doubleClickZoom.

- Restore doubleClickZoom=true default (breaking change avoidance)
- Add regression test for runtime controller prop propagation
- Add test/apps/gesture-timing for interactive delay measurement

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
@chrisgervang
chrisgervang merged commit 727dfa5 into master Jul 10, 2026
6 checks passed
@chrisgervang
chrisgervang deleted the x/mjolnir-up branch July 10, 2026 18:19
@chrisgervang chrisgervang added this to the v9.4 milestone Jul 14, 2026
@chrisgervang chrisgervang mentioned this pull request Oct 7, 2026
12 tasks done
chrisgervang added a commit that referenced this pull request Oct 29, 2026
…kZoom is off (#10384) (#10973)

* fix(core): remove the 300ms click delay when doubleClickZoom is off (#10384)

Backport of the click-delay part of #10422 (merged into master via #10416)
to 9.3-release, without the DoubleClickDrag recognizer.

- The dblclick recognizer starts disabled, and Deck watches dblclick for
  picking, so only the controller's doubleClickZoom option enables it
- Clone the view when the controller prop changes so runtime changes apply
- Interaction tests; they read the protected eventManager field because
  Deck.getEventManager() isn't on 9.3

* fix(core): copy the views array before applying the controller prop

Cloning the first view wrote into the caller's views array, which throws
when the array is frozen.

* test(core): keep the frozen views array typed as View[]
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.

4 participants