Null pointer in Draggable.js
See original GitHub issuein Draggable.js
This line:
var first = e.touches ? e.touches[0] : e,
will cause a null pointer here:
this._startPoint = new Point(first.clientX, first.clientY);
if e.touches is [] which can happen.
It should probably be changed to:
var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
as is the case further down in the same class.
I stumbled across this issue since leaflet breaks when dragging if it is in a popout from the flexlayout-react package.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
jQuery Draggable with Bootstrap Tooltip TypeError
The below code throws tens of errors "TypeError: e.$element is null" in Firefox or "Uncaught TypeError: Cannot read property 'trigger' of null" ...
Read more >Drag'n'Drop with mouse events - The Modern JavaScript Tutorial
So here we'll see how to implement Drag'n'Drop using mouse events. ... So after swift move the pointer can jump from the ball...
Read more >ondragstart Event - W3Schools
The ondragstart event occurs when the user starts to drag an element or a text selection. Drag and drop is a common feature...
Read more >Marker | Maps JavaScript API - Google Developers
Return Value: string|null|undefined. Get the mouse cursor type shown on hover. getDraggable. getDraggable(). Parameters: None.
Read more >d3-drag - npm
If the subject is null or undefined, no drag gesture is started for this pointer; however, other starting touches may yet start drag...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m also affected by this issue.
e.touches
is an empty array and the check fails because it does not take into account javascript ‘truthiness’. Admittedly I’m using Leaflet from a GWT script, inside iframes etc. so this may be a corner case, but I would consider fixing this and making the check more robust anyway. Actually the very same check in the_onMove
method already checks empty arrays.The event object does have
.clientX
and.clientY
properties. The issue is that ite.touches = []
and therefor truthy, makingfirst undefined
in the linevar first = e.touches ? e.touches[0] : e,
instead ofe
.I’ve no idea why
e.touches = []
in the case where leaflet is in a secondary window, but it seems to be the case.I’m not very familiar with the code so I’m not sure if this should be fixed to
var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
orvar first = (e.touches && e.touches.length > 0 ? e.touches[0] : e),
or something else.This change together with
element.ownerDocument
instead ofdocument
in a couple of places seems to make leaflet work correctly in the popout window.I think there are at least two ways to solve the second problem. Either an option could be provided to override which document to use, or alternativly the ownerDocument of the map container for binding events could always be used. The first may be safer to not break backwardcompatibility but the second may fix things automatically in many cases.