-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Safari 13.x t.addEventListener is not a function #560
Comments
@davidjerleke I added a PR to check if the addEventListener exist before calling it that might help just not throw errors on older browsers and work limited |
Hi @hamidrezahanafi, First of all, thank you for wanting to contribute to Embla Carousel. The intention to help improve this library is always appreciated 👍! A friendly reminder: Before starting any work, always start a new discussion first. The reason why I'm mentioning this is because this could prevent you from doing unnecessary work. Looking at the usage statistics, it seems like Best, |
Hi everyone. I'm always in favour of supporting new features, but usually when it comes to complex properties like flex's gap - it requires a lot of overhead and in such cases it's worth explicitly defining the list of supported browsers on the product page to avoid wasting energy and bloating the codebase with unnecessary fallbacks. People knowing about this use either an outdated method or make a wrapper with a simple check and a small fallback. My proposal is to add a small fallback in your helper function code - it's not difficult for you and won't add a lot of code to the bundle but unlike the current behaviour or the proposed PR - it will work everywhere. before node.addEventListener(type, handler, options)
listeners.push(() => node.removeEventListener(type, handler, options)) after if ('addEventListener' in node) {
node.addEventListener(type, handler, options)
listeners.push(() => node.removeEventListener(type, handler, options))
} else {
node.addListener?.(handler);
listeners.push(() => node.removeListener?.(handler))
} If for some reason such a condition may seem redundant to you - I'll accept even the current PR |
Hey @davidjerleke yeah will start the discussion first in the future Thanks for the reminder. |
@7iomka thank you for joining the discussion. Thanks for the additional input @hamidrezahanafi. I don't think that "Changing this will prevent this from crash in an old browser" is a good argument for fixing it. We can't start supporting IE11 because Embla will crash there simply because Embla doesn't support IE11 anymore. However, since you have proof that some people (although not many based on statistics) are still using if ('addListener' in node) {
node.addListener(handler);
listeners.push(() => node.removeListener(handler))
} else {
node.addEventListener(type, handler, options)
listeners.push(() => node.removeEventListener(type, handler, options))
} I would be happy to add this too Embla core for now. But we need to test this on Best, |
Hey @davidjerleke Thanks for understanding untitled_aAXrp4xh.mp4 |
Thanks @hamidrezahanafi. I'll have to do some functionality testing before I can be sure that all features work in Safari 13 before merging the PR. Best, |
Hey @davidjerleke, Is there any update on this? Let me know how I can help with testing. |
Hi @hamidrezahanafi, Yes that would be helpful 👍. I'm thinking that we should mainly test the following things:
emblaApi.on('slidesInView', (emblaApi) => {
console.log(emblaApi.slidesInView())
}) Any help appreciated. Please make sure to test the latest version Best, |
Hey @davidjerleke I tested following on Safari 13 |
Thanks a lot for your efforts @hamidrezahanafi 👍. I've been busy rewriting all tests for this project from scratch before the stable v8 release so any help with other stuff is appreciated. This speeds up things. I just merged your PR and will release it with version |
Thanks for all your help @hamidrezahanafi! I just released this feature with version |
Bug is related to
Embla Carousel version
Describe the bug
t.addEventListener is not a function on Safari 13.x
This comes adding event to mediaHandlers
mediaHandlers.add(query, 'change', reActivate));
Rest of the error:
`TypeError: t.addEventListener is not a function. (In 't.addEventListener(r,o,i)', 't.addEventListener' is undefined)
./node_modules/embla-carousel/embla-carousel.esm.js at line 192:10
function EventStore() {
let listeners = [];
function add(node, type, handler, options = {
passive: true
}) {
node.addEventListener(type, handler, options);
listeners.push(() => node.removeEventListener(type, handler, options));
return self;
}`
CodeSandbox
It only happens on older browsers
Steps to reproduce
Expected behavior
Is it possible to support older browsers?
Additional context
The text was updated successfully, but these errors were encountered: