To replicate:
The error is related to this query in glide sourcecode:
this.track = this.root.querySelector(TRACK_SELECTOR);
this.root doesn't exist so it throws error glide.js:1308 Uncaught TypeError: Cannot read property 'querySelector' of undefined
It would be good if glide had guard condition that prevents errors when it can't find element with a provided class.
I also noticed this. Surely the script should just bail if there is no matching element as early as possible.
Yep - in my particular use case where I don't have the Glide component on a page at all times, this is certainly annoying.
You have to verify if HTMLElement exists before initializing glide instance. The component base structure makes it hard to bail that as there is no single point where this could be tackled down.
var slider = document.querySelector('.glide');
if (slider) {
var glide = new Glide(slider);
glide.mount();
}
Also more explanation here #283
This is a very weird behavior. This is really the only thing that bothers me with this awesome library.
Most helpful comment
You have to verify if HTMLElement exists before initializing glide instance. The component base structure makes it hard to bail that as there is no single point where this could be tackled down.
Also more explanation here #283