Leaflet: Leaflet 1.7.1 causes 2 click events to be emitted by Leaflet Controls in Safari
Steps to reproduce Steps to reproduce the behavior:
- set up a basic map, with a control that has a button in it, which listens for click events and posts the events to the console
- click the button in the control using Safari on a Mac
- see two click events in the console, one with
isTrusted:true
and another withisTrusted:false
attributes
(Using ‘force touch’ to click the button on a trackpad results in only a single click event being emitted, but it also triggers the Safari preview popup.)
Expected behavior
There should only be one click event emitted, with the isTrusted:true
attribute.
Would Leaflet be able to safely filter out the click events with isTrusted:false
?
Current behavior
In version 1.6 the expected behaviour is observed. In version 1.7.1 Chrome exhibits the expected behaviour, but Safari doesn’t.
The differences between the two events are included below.
MouseEvent 1:
MouseEvent
_simulated: true
composed: false
isTrusted: false
layerX: 15
layerY: 28
offsetX: 15
offsetY: 28
pageX: 410
pageY: 46
screenX: 1390
screenY: 189
timeStamp: 499337
webkitForce: 0
x: 410
y: 38
MouseEvent 2:
MouseEvent
composed: true
isTrusted: true
layerX: 15
layerY: 20
offsetX: 15
offsetY: 20
pageX: 410
pageY: 38
screenX: 1390
screenY: 189
timeStamp: 538265
webkitForce: 1
x: 410
y: 38
_simulated
, composed
, isTrusted
and perhaps webkitForce
seem to be the key differences, but it also seems odd that there are different timestamps and Y dimensions between the two events.
Environment
- Leaflet version: 1.7.1
- Browser (with version): Safari 13.1.2
- OS/Platform (with version): OS X 10.13.6 and 10.15.6
Additional context
I noticed this after OpenStreetMap updated to the latest version of Leaflet, where the issue manifests itself by preventing some of the map tools to be used as the first event toggles a tool on and the second toggles it off. Related issue posted at https://github.com/openstreetmap/openstreetmap-website/issues/2811
Minimal example reproducing the issue
Please see https://codepen.io/dankarran/pen/JjXMXzd
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 47
- Comments: 63 (17 by maintainers)
Links to this issue
- spip-contrib-extensions/gis - gis - SPIP on GIT
- spip-contrib-extensions/gis - gis - SPIP on GIT
- spip-contrib-extensions/gis - gis - SPIP on GIT
- spip-contrib-extensions/gis - gis - SPIP on GIT
- spip-contrib-extensions/gis - gis - SPIP on GIT
- spip-contrib-extensions/gis - gis - SPIP on GIT
- spip-contrib-extensions/gis - gis - SPIP on GIT
- django - Popup does not open when clicking on marker safari - Stack Overflow
Commits related to this issue
- revert to leaflet 1.6.0 to fix Safari issues See https://github.com/Leaflet/Leaflet/issues/7255 — committed to bmcbride/gps-map by bmcbride 4 years ago
- Downgrade leaflet to 1.7.0 Workaround for https://github.com/Leaflet/Leaflet/issues/7255. — committed to WatWowMap/MapJS by Mygod 4 years ago
- Fixed yet another issue with Safari See https://github.com/Leaflet/Leaflet/issues/7255 — committed to bopen/leaflet-area-selection by keul 4 years ago
- Workaround safari double-click issue: https://github.com/Leaflet/Leaflet/issues/7255#issuecomment-732082150 — committed to erik-stephens/trail-blog by deleted user 4 years ago
- Workaround safari double-click issue https://github.com/Leaflet/Leaflet/issues/7255 — committed to edenb/livemap-ui by edenb 4 years ago
- Use master branch of leaflet Desktop Safari is broken on 1.7.1. https://github.com/Leaflet/Leaflet/issues/7255 I built a version of the master branch and deployed to to NPM. — committed to stadtnavi/digitransit-ui by leonardehrenfried 4 years ago
- Use master branch of leaflet Desktop Safari is broken on 1.7.1. https://github.com/Leaflet/Leaflet/issues/7255 I built a version of the master branch and deployed to to NPM. — committed to stadtnavi/digitransit-ui by leonardehrenfried 4 years ago
- disable tap on map temp fix for https://github.com/Leaflet/Leaflet/issues/7255 — committed to brunob/leaflet.fullscreen by brunob 3 years ago
- disable tap on map temp fix for https://github.com/Leaflet/Leaflet/issues/7255 — committed to brunob/leaflet.fullscreen by brunob 3 years ago
- disable tap on map temp fix for https://github.com/Leaflet/Leaflet/issues/7255 — committed to brunob/leaflet.fullscreen by brunob 3 years ago
- leaflet 1.7.1 hinzufügen aktuell mit doppel-click bug in Safari :/ https://github.com/Leaflet/Leaflet/issues/7255 — committed to ssp/Gedenktafeln by ssp 3 years ago
- Fix multiple click events on single tap by downgrading leaflet See: https://github.com/Leaflet/Leaflet/issues/7255 — committed to chacal/weatherapp by chacal 3 years ago
- Minor fixes Fixing incorrect styling of Leaflet popups in production deployments. Fixing popups in Safari as per https://github.com/Leaflet/Leaflet/issues/7255. Removing test page. — committed to binghamchris/paddelbuch by binghamchris 3 years ago
- fix: disable MapContainer.tap for Safari See: https://github.com/Leaflet/Leaflet/issues/7255 — committed to team-azb/route-bucket-frontend by shugo256 3 years ago
- Workaround to fix map popup in Safari See https://github.com/Leaflet/Leaflet/issues/7255. — committed to cyclosproject/cyclos4-wordpress-plugin by sandrab 3 years ago
- Fix popups in Safari Leaflet v1.7.1 has a bug (https://github.com/Leaflet/Leaflet/issues/7255) where clicking pins will not render popup messages in Safari. The quick solution identified is to disab... — committed to OpenTechStrategies/SimpleMaps by slifty 3 years ago
- fix(map): fix click events being fired multiple times on Safari https://github.com/Leaflet/Leaflet/issues/7255 — committed to balintant/topographic-contour-maps by balintant 3 years ago
- Prevent double click events in Safari This can be reverted when Leaflet/Leaflet#7255 is addressed. Fixes #414 — committed to kabalin/pastvu by kabalin 3 years ago
- Prevent double click events in Safari This can be reverted when Leaflet/Leaflet#7255 is addressed. Fixes #414 — committed to kabalin/pastvu by kabalin 3 years ago
- Fix tap issue on mobile Safari - fixes issue on mobile Safari where tap for popup only works when at base of marker; otherwise appears and disappears quickly - add tap: false as map config - refere... — committed to awbirdsall/place-pairs by awbirdsall 3 years ago
I ran into this problem in firefox as well (and mobile safari). I was not able to reproduce it reliably but the hint that it comes from the tap option led me to the solution which disables tap entirely as I apparently don’t need it to open the popup, even on mobile safari:
disabling tap altogether fixes this for me on safari (using leaflet from react-leaflet) and all my tap events still work.
works great! Not sure what “tap” actually does since my markers, panning etc all still work.
source: https://bleepcoder.com/leaflet/694192486/leaflet-1-7-1-causes-2-click-events-to-be-emitted-by-leaflet
edit: says @eikes comment was pinned but I actually had to “unhide” it to see it
@AduchiMergen we are currently in the final phase before releasing 1.8.0. We think we release it with march
For anyone using Vue-Leaflet, setting tap to false seems to work to resolve the issue, but remember that vue-leaflet only allows some options to be passed as props to the map component directly, for the rest (like ‘tap’) you need to pass a custom ‘options’ object, as per: https://vue2-leaflet.netlify.app/faq/#how-can-i-specify-leaflet-options-that-aren-t-part-of-a-component-s-props
Disabling tap fixed the problem for me also. But since I’m using React-Leaflet, I don’t use
L.map()
. Instead, the MapContainer component has atap
prop that can be used for disabling tapping.Thank you for this solution, @eikes! I ran into this issue today and that solved it.
As appeared, the same issue affects not only desktop Safari, but also legacy Edge (and who knows what else). AFAIK atm
tap
handler is needed for iOS only.So… May be we should change
map.options.tap
default tofalse
.For the sake of clarity: that example is using
Note that this issue also causes
bindPopup
to not work with markers:@SpencerKaiser can you try
leaflet@beta
?This issue prevents menus from working on Safari. For example, openstreetmap loses its map tools. As no one is assigned to this bug, it may not get attention.
The same problem happens to me and only happens in Safari. Chrome and Firefox are only firing the event once MacOS 10.15.6 and Safari 14.0.
I temporarily downgraded Leaflet to 1.6 and everything works normally.
If the JS at https://s3.amazonaws.com/leafletjs-cdn/content/leaflet/master/leaflet-src.js is the latest version, it’s still firing two click events on iOS Safari.
👮
~The
off topic
police are going a bit overboard here 🙄 the comment directly above this one is directly related to this issue…~Edit: Thanks for making the one above on topic again 😉
ETA a few days. Very likely at the end of the week.
If 1.8.0 includes breaking changes, why isnt it a 2.0.0 release then??
@Falke-Design The 1.8 is quite big update which includes breaking changes IMHO bugfix should be released in a patch update 1.7.2
https://s3.amazonaws.com/leafletjs-cdn/content/leaflet/master/leaflet-src.js ^ this version seems to work way better than
1.7.1
in desktop Safari 14.0. tap or click fires only once 👍If it helps as a quick fix as a stopgap (and doesn’t break other things), commenting out that simulated event does seem to work for me in both Chrome and Safari on iOS…
https://github.com/Leaflet/Leaflet/blob/4f32a5e83525a3a42980c974e48712b058510eb5/src/map/handler/Map.Tap.js#L100
Unsure whether this is the same issue (so please forgive tagging onto end of existing ticket), but shift-drag to zoom in is also broken in 1.7.1 on desktop Safari. Happy to open a new issue if #7260 hasn’t fixed this too.