question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null pointer in Draggable.js

See original GitHub issue

in 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:open
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
psimonazzicommented, Jul 8, 2021

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.

2reactions
JonatanRydhcommented, May 7, 2021

The event object does have .clientX and .clientY properties. The issue is that it e.touches = [] and therefor truthy, making first undefined in the line var first = e.touches ? e.touches[0] : e, instead of e.

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), or var first = (e.touches && e.touches.length > 0 ? e.touches[0] : e), or something else.

This change together with element.ownerDocument instead of document 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found