Issue with variants/images/others (mediaGallery.setActiveMedia issue)

We’re currently having a really strange issue with a store that we look after for a client

https://www.ediblehealth.com/products/hydrolysed-bovine-collagen-powder

When the Size variations are changed, it gives an error:

Uncaught TypeError: mediaGallery.setActiveMedia is not a function

This error is stopping images and prices from changing and also stopping the Add to Cart button from being clickable, so we need to resolve it. I’ve been through the global.js and the media-gallery.js files so many times now and it seems to be in relation to this line in the global.js, but this is not something that we’ve ever modified and even replacing these two entire JavaScript files with the default Dawn stuff does not fix the issue

mediaGalleries.forEach(mediaGallery => mediaGallery.setActiveMedia(${this.dataset.section}-${this.currentVariant.featured_media.id}, true));

There must be something else in the website that’s causing this issue but we cannot figure out what. Has anybody else came across this error? The theme is a customisation of Dawn 7.0.1, I tried to install another copy of the base Dawn 7.0.1 theme and that seems to work fine so I don’t think it’s an app conflict?

It sounds like the issue is specific to your customized version of the Dawn theme. The error suggests that the setActiveMedia function might not be properly initialized or is being called before the media gallery is ready. Since the base Dawn theme works fine, the problem likely lies in your customizations

Just to add as I thought it was worth testing - I’ve zipped up this exact customised theme and tested it on an old development store we had for the same client (so really similar setups with the products etc) and it worked absolutely fine.

Even when reinstalling some of the same apps that I presumed may have caused the conflict, it still works. Quite lost on this one!