Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to preventDefault inside passive event listener invocation #334

Open
sergeybakhar opened this issue Mar 27, 2019 · 39 comments
Open

Comments

@sergeybakhar
Copy link

Hi!

Thanks for the awesome slider!

When I click on bullets I get "Unable to preventDefault inside passive event listener invocation" in Chrome.

Can I fix it somehow?

I've read about supporting IE11 ;)

Google Chrome 73.0.

@thezaff
Copy link

thezaff commented Apr 2, 2019

Hi!

Thanks for the awesome slider!

When I click on bullets I get "Unable to preventDefault inside passive event listener invocation" in Chrome.

Can I fix it somehow?

I've read about supporting IE11 ;)

Google Chrome 73.0.

I am experiencing the same problem on the same Chrome version. Did you find a solution?

@jamesmosier
Copy link

jamesmosier commented Apr 3, 2019

This article from Google explains it a bit, but their proposed solution of adding the CSS property touch-action: none to the elements firing the event isn't working. I tried putting this on every single Glide element with no luck. My issue is with the next/previous controls, so in theory putting that style on the button element should fix it but I couldn't get it to work.

Additionally here is a chromium issue that details it a bit more.

@sergeybakhar
Copy link
Author

Hi!

Unfortunately, I haven't found a solution. And I've tried 'touch-action' everywhere, but with no luck, too.

@thezaff
Copy link

thezaff commented Apr 4, 2019

Hi!

Unfortunately, I haven't found a solution. And I've tried 'touch-action' everywhere, but with no luck, too.

This article from Google explains it a bit, but their proposed solution of adding the CSS property touch-action: none to the elements firing the event isn't working. I tried putting this on every single Glide element with no luck. My issue is with the next/previous controls, so in theory putting that style on the button element should fix it but I couldn't get it to work.

Hey!

I have just fixed it on my project.
Turns out I've had wrong values for data-glide-dir attribute of buttons (.glide__arrow). I've had prev and next values, but when I changed them to < and > respectively, it worked properly.

I've had this markup:

<div class="glide__arrows" data-glide-el="controls">
    <button class="glide__arrow glide__arrow--left" data-glide-dir="prev"></button>
    <button class="glide__arrow glide__arrow--right" data-glide-dir="next"></button>
</div>

Instead, I had to use this markup from glide docs

<div class="glide__arrows" data-glide-el="controls">
    <button class="glide__arrow glide__arrow--left" data-glide-dir="<">prev</button>
    <button class="glide__arrow glide__arrow--right" data-glide-dir=">">next</button>
</div>

Just alter the data-glide-dir attribute values to < and > if you have prev and next instead.

@jamesmosier
Copy link

jamesmosier commented Apr 4, 2019

Hi @thezaff, thanks for the thought. Unfortunately that's already what I had in there for the data-glide-dir attribute.

When testing the demos on the Glide site and using Chrome Dev Tools to emulate a touch device, the error is still present.

@romansh
Copy link

romansh commented Apr 10, 2019

The same here with dotted navigation. I have tried a lot of things but without any success.

@viiiprock
Copy link

same here

@poldixd
Copy link

poldixd commented May 17, 2019

Same here! Chrome 74

@timtheone
Copy link

There is an open PR to fix this issue: #351.
CC: @jedrzejchalubek .

@nicholashamilton
Copy link

Looks like their utility located in '../utils/detect-passive-event' is not working. event.preventDeault() should not be called on a passive event listener, which in this case it is.

@gozenc
Copy link

gozenc commented Jul 1, 2019

Changing line 3249 of glide.js's event.preventDefault(); to event.stopPropagation(); solves the problem for now.

@nicholashamilton
Copy link

quick fix for now

const glideBullets = Array.from(this.view.querySelectorAll('.glide__bullet'));

glideBullets.forEach((el) => {
el.addEventListener('click', (e) => {
e.stopPropagation();
});
});

@Roye7777777
Copy link

Roye7777777 commented Jul 16, 2019

Although the slider works normally, despite changing event.preventDefault() to event.stopPropagation() and even adding {passive: false} as an option to the function, the error keeps on appearing. It is, however, only in Google Chrome 75 DevTools' device toolbar (for responsive testing). On my phone, I obviously don't get any errors, which would make it seem ok, but it causes other javascript on the page to not function at all instead, which is not ok sorry, I checked it again and I can confirm this doesn't break the rest of the scripts.

@PezCoder
Copy link

PezCoder commented Aug 1, 2019

@jedrzejchalubek @ahukkanen I can see the fix for this issue has been merged in #351 but it's not available on npm yet.

Is it possible to push a release with appropriate version to npm for all the 21 commits (v3.3.0...master) that's been pushed since v3.3.0 ?

@phpMagpie
Copy link

Just used the dist folder to pull down latest js files and this fix is not in there either.

@nicklee
Copy link

nicklee commented Aug 29, 2019

Getting this as well on the latest release

@janbiasi
Copy link

Same here ...

@iecorp
Copy link

iecorp commented Sep 2, 2019

Same here...

1 similar comment
@MLDMoritz
Copy link

Same here...

@Jucifer
Copy link

Jucifer commented Sep 9, 2019

saaaaame

@idpokute
Copy link

same here...

@PezCoder
Copy link

I understand the intentions of people doing same here's are right but a suggestion.

You should do +1 reaction 👍on the comment if you find something which works as a fix or resembles your issue because of two reasons:

  1. A new comment like these bring unnecessary attention to the thread for the people who has subscribed to the thread
  2. 👍 are a way to quickly scan through a thread & know what comments has worked for people & what doesn't, reading through a thread otherwise with tons of same here just makes it complicated

@AbanoubNassem
Copy link

probably it's related to same issue here : inuyaksa/jquery.nicescroll#799 (comment) ?

@studiogalaxie
Copy link

Hi, the issue still exist. Is there any fix for that problem ?

@gilbertlucas46
Copy link

gilbertlucas46 commented Apr 21, 2020

Removing data attributes and manually adding click events works for me.

<div class="glide__arrows">
    <button class="glide__arrow glide__arrow--left"></button>
    <button class="glide__arrow glide__arrow--right"></button>
</div>
const ArrowRight = document.querySelector('.glide__arrow--right');
ArrowRight.addEventListener('click', () => {
  Slider.go('>');
});

const Arrowleft = document.querySelector('.glide__arrow--left');
Arrowleft.addEventListener('click', () => {
  Slider.go('<');
});

@jrmarqueshd
Copy link

jrmarqueshd commented Jun 9, 2020

At ReactJs I was able to solve this by creating a function that makes navigation for me!

I did the following to make it work without the error message:
I created a function that handles the navigation of the arrows and bullets

const sliderGoTo = (direction) => {
   this.glide.go(direction);
}

And on the call of events I did the following:
Example for calling the next slider

<button onClick={() => sliderGoTo(">")} className="glide__arrow glide__arrow--next">{">"}</button>

Example for calling the next slider through the bullets

<button key={index + ""} className={`glide__bullet ${activeSlider === index ? "glide__bullet--active" : ""}`} onClick={() => sliderGoTo("=" +  index)} />

After that, just remove the date attributes that we passed previously in the control elements.

This is easily replicated in pure JavaScript, in case you need help!

@psdon
Copy link

psdon commented Jul 6, 2020

any update?

@Vince-vegas
Copy link

The error will show when you open the console but if it's not GlideJs will not throw an error to the console

This would help

@Keither
Copy link

Keither commented Nov 18, 2020

i removed this code t.preventDefault() in min file, and working fine (no error Unable to preventDefault inside passive event listener invocation)
sorry my english not good!

@karakunai
Copy link

karakunai commented Dec 19, 2020

After trying some solutions above, in my case with NextJS I found that it would just trigger another bug like this one #371, so I've tried to append these buttons the parent element and set data-glide-dir attribute there manually. Example

const controlParent = createRef()
useEffect(() => {
    let leftControl = document.createElement("button")
    leftControl.setAttribute("class", "glide__arrow glide__arrow--left")
    leftControl.setAttribute("data-glide-dir", "<")
    leftControl.textContent = "prev"
    controlParent.current.appendChild(leftControl)
}, [])

....

and then

<div className="glide__arrows" data-glide-el="controls" ref={controlParent}></div>

I can confirm on my end that there's no error on my dev console with this one. Please have a try and let me know how it performs on your end.

@karakunai
Copy link

And I just wanna say Merry Christmas, hopefully we can get some fixes in the near future, because there's no other library like GlideJS... sadge

@AlexaContreras
Copy link

Hi guys, I fixed it by changing the glide.esm.js file y node modules line 3243 from event.preventDefault() to event.stopPropagation();

@SelfTaughtCoder78704
Copy link

SelfTaughtCoder78704 commented Aug 6, 2021

I removed this from the source code: t.preventDefault(), -- take notice of the comma as well.
you can find it in the error being logged.
App still works -- no errors at all

@Michaelvons
Copy link

Hi guys, I fixed it by changing the glide.esm.js file y node modules line 3243 from event.preventDefault() to event.stopPropagation();

If you are using Webpack, remember to restart your dev server after saving the edit

@bastien70
Copy link

Maybe a release with the fix ?

@Ayagoumi
Copy link

Experiencing the same issue.

@vitorblsantoss
Copy link

vitorblsantoss commented Oct 19, 2021

Has an way to solve the problem? Only happens on mobile...

@sevdas
Copy link

sevdas commented Oct 27, 2021

Hello,
I am also experiencing the same issue, please see below for more details.
Screenshot 2021-10-27 at 10 01 08

As seen on the screenshots it happen to throw an error on preventDefault() and work in stopPropagation() within glide.esm.js folder, however I am not able to fix it permanently. Will glide have an update on it ?

Screenshot 2021-10-26 at 12 02 10

Screenshot 2021-10-26 at 12 02 27

@MilanTearMaras
Copy link

Has an way to solve the problem? Only happens on mobile...

Same here! Is there a solution yet?

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

No branches or pull requests