mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

Unable to preventDefault inside passive event listener invocation.

Open radekdob opened this issue 5 years ago • 18 comments
trafficstars

Hello,

mapbox-gl-js version: 1.12 mapbox-gl-draw version: 1.2.0

Steps to Trigger Behavior

  1. Add Mapbox Draw control to mapbox map.
  2. Open in browser and switch to touch device.
  3. Click on map and check console

Just open official web and switch to device toolbar in developer console. Touch a map and check console. https://docs.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/

Expected Behavior

Should not generate that issue. If any mapbox layers was added, they are not reacting to click/touch event. Only drawing tools and features which was drawed are "alive".

Actual Behavior

After clicking on map when mapbox draw was added as control, mapbox draw generates error.
Error text : " Unable to preventDefault inside passive event listener invocation."

radekdob avatar Oct 25 '20 11:10 radekdob

Ok, I guess this error "Unable to preventDefault inside passive event listener invocation." is not bad behaviour. The issue is that when I was using only pure mapbox, it reacted on "click" event both on touch devices and mouse. When I added Mapbox draw, event from mapbox mouse click started listening only on mouse click, not as previously on touch too.

Maybe it will help somebody in the furure :)

radekdob avatar Oct 25 '20 15:10 radekdob

@radekdob I confirm. The problem is urgent.

petrovnn avatar Feb 10 '21 05:02 petrovnn

Double confirm -- this is a problem for us as well.

walwoodr avatar Feb 24 '21 20:02 walwoodr

Does someone got the solution to this problem

kartikmalhotra avatar Mar 06 '21 06:03 kartikmalhotra

I encountered the same problem. I wanted to draw on my mobile phone, but I was stumped by this problem.

hahaxiaowai avatar Apr 01 '21 01:04 hahaxiaowai

I encountered the same problem. When I add draw tool, other layers click event stop working for mobile browsers. However, the click event works fine for desktop browsers.

zafrii avatar Apr 03 '21 15:04 zafrii

+1

sanjay-k7r avatar Apr 26 '21 20:04 sanjay-k7r

Running into the same problem, anyone come up with a solution?

bren96 avatar May 27 '21 20:05 bren96

@bren96 this is how I solved it

map.on('click', 'points', function (e) {
    show_popup(e);
});


map.on('touchend', 'points', function (e) {
    show_popup(e);
});

i.e., by adding events for both 'click' and 'touchend'

zafrii avatar May 28 '21 07:05 zafrii

This statement is not correct for mobile devices https://github.com/mapbox/mapbox-gl-draw/blob/2b9ce3e58e3695c018a48b6fca78ed1a9d1b67c2/src/events.js#L82

luisgurmendezMLabs avatar Jul 28 '21 14:07 luisgurmendezMLabs

I confirm. The problem is urgent !!!

hu-bobo avatar Sep 15 '21 05:09 hu-bobo

I am using mapbox-gl-draw 1.3.0 in October 2021 and the "Unable to preventDefault inside passive event listener invocation." error is still there :(

NicoSerranoP avatar Oct 11 '21 00:10 NicoSerranoP

Can confirm. Whenever I draw on the map this error comes up and the draw.create event never fires.

mapbox-gl: 2.6.1 mapbox-gl-draw: 1.3.0

scheepers avatar Jan 02 '22 09:01 scheepers

mapbox-gl: 2.7.0 Whenever I move the map this log appears, ok, google chrome appears Has this problem been solved, hurry up

kekeshuzhen avatar Mar 03 '22 09:03 kekeshuzhen

+1

tibz7 avatar Mar 04 '22 15:03 tibz7

18 May 2021, The error is still there. Had to remove the Mapbox Draw and look for other alternative

eirfan avatar May 18 '22 14:05 eirfan

Problem still here I can confirm too. I am using pop-ups and drawing tools.

nlintas avatar Aug 24 '22 16:08 nlintas

I'm using 'moveend' event and getting this error.

igorbrandaodev avatar Aug 30 '22 18:08 igorbrandaodev

Still this problem exists.

erhanask avatar Nov 02 '22 08:11 erhanask

Still an issue here

PedroVenancio avatar Jan 07 '23 01:01 PedroVenancio

I lived with the workaround @zafrii provided on May 28, 2021 quite some time but the error still occurs in the console and causes some further problems. E.g. if a Popup with option {closeOnClick: true} is open - a touch on any other place on the map does not close it.

So I found a fix for the whole problem. As long as Mapbox guys didn't merge my PR, you can use my fork of mapbox-draw to get rid of this shit by e.g.: npm install danielsippel/mapbox-gl-draw

The fix works for all browsers that support EventListenerOptions, workaround mentioned by @zafrii is not needed any longer.

Tested on:

  • Chrome mobile (current); Android13; Google Pixel 6a
  • Firefox mobile (current); Android13; Google Pixel 6a
  • Safari mobile; iOS v15.4; iPhone 13 Pro Max

danielsippel avatar Jan 18 '23 05:01 danielsippel

@chriswhong @mourner

Can you guys please review my PR (or at least find someone who does) and get this basic map feature, what mapbox-draw is, running on more complex maps ("with popups") for mobile browsers again? Thanks.

danielsippel avatar Jan 18 '23 08:01 danielsippel

@danielsippel I have reviewed you PK , it works pretty well , But i don't know why my project file can not access the theme file from the lib folder , so i manually added that to my project, Good Job, it do fix that issue but ,

Usmankt1999 avatar Feb 13 '23 14:02 Usmankt1999

@Usmankt1999 Thanks for testing. Since my fix has been merged into the main repo, my fork is not necessary any longer.

You can switch back to the main repo: npm install @mapbox/mapbox-gl-draw

Changelog: https://github.com/mapbox/mapbox-gl-draw/releases/tag/v1.4.0

danielsippel avatar Feb 13 '23 15:02 danielsippel

@danielsippel So , we need to re-install the mapbox/mapbox-gl-draw ,

But i think its fine , i also wanted to customised the theme file so i downloaded it from your repo , i think it will work fine even if i am using npm install danielsippel/mapbox-gl-draw , Right?

Usmankt1999 avatar Feb 13 '23 15:02 Usmankt1999

Works fine, but you will miss future fixes/features, which go to the main repo only.

danielsippel avatar Feb 13 '23 16:02 danielsippel

@danielsippel , Thanks you for your response alright i will use the main repo then :)

Usmankt1999 avatar Feb 13 '23 16:02 Usmankt1999

Hi all,

I'm reopening this because I'm going to revert the fix https://github.com/mapbox/mapbox-gl-draw/pull/1158 since it currently breaks the touch events as reported in https://github.com/mapbox/mapbox-gl-draw/issues/1154. I missed it during the manual testing, and we'd need to look for a different way to do it. Sorry for the inconvenience.

stepankuzmin avatar Feb 14 '23 15:02 stepankuzmin

+1.

Please fix this!

dollysingh3192 avatar Feb 27 '23 07:02 dollysingh3192

Victims++

a-hariti avatar Mar 07 '23 19:03 a-hariti