mhirdes / go_maps_ext

Google Maps Extension for TYPO3
MIT License
21 stars 31 forks source link

Uncaught (in promise) TypeError: getGoMapsExtControllerById(...) is undefined #109

Closed mediaessenz closed 7 months ago

mediaessenz commented 11 months ago

Sometimes it happens, that a map is not shown and this error appears in the js console: Uncaught (in promise) TypeError: getGoMapsExtControllerById(...) is undefined

I think it's a timing problem, if cached js is used or not.

I could imagine, that this can be fixed by wrapping the getGoMapsExtControllerById(el.id).initialize(); call in a DOMContentLoaded event listener like so:

window.goMapsExtLoaded = function() {
    document.addEventListener('DOMContentLoaded', () => {
        const maps = document.querySelectorAll('.js-map');
        maps.forEach(function (el) {
            getGoMapsExtControllerById(el.id).initialize();
        });
    })
}
mhirdes commented 9 months ago

This should fix the error. Maybe you can test it?

mediaessenz commented 9 months ago

Why not using the DOMContentLoaded event?

This event is fired exact at that time when the DOM content is loaded. This way it is not neccecarey to check the readystate in a loop ...

mhirdes commented 9 months ago

Thanks for your feedback. What about this solution? The problem is, that it can be that the event was already triggered and the API and so the callback function was not loaded.

So I have to check both, the DOM is ready and the API was loaded.

mediaessenz commented 9 months ago

Just changing setTimeout with a DOMContentLoaded listener will not work imo. How do you load the api code?

mhirdes commented 9 months ago

I wrote you a message via Slack. Maybe we can chat there

nordowl commented 8 months ago

Any updates on this? The proposed fix sadly doesn't work for me as it introduces a new error: Uncaught (in promise) TypeError: this.gme is undefined

mhirdes commented 8 months ago

Did you test the current main branch?

nordowl commented 8 months ago

I didn't. We extended gomapsext.js, so I just tried pasting the fix into that file. Will test again using the updated branch and report back.

ingeniumdesign commented 7 months ago

we have the same problem: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'initialize')

mhirdes commented 7 months ago

Please use the current version 6.1.1