Recent update has introduced a Javascript error that breaks site features
-
After a recent update, I’ve noticed we started getting the below error on every page load.
TypeError: Cannot read properties of null (reading ‘addEventListener’)
at window.onload (callout.js:26:60)By itself, it’s not a huge deal, but if you try to concat / minify Javascript with something like WP Rocket, this error can cause the rest of the JS in the load path to not load properly.
The issue on admin/js/callout.js is that this block fails if there’s no element by that ID on the page:
document.getElementById("toplevel_page_sb-instagram-feed").addEventListener("mouseenter", (event) => {
if (!document.body.classList.contains('index-php')) {
positionCalloutContainer()
}
});
document.getElementById("toplevel_page_sb-instagram-feed").addEventListener("mouseleave", (event) => {
if (!document.body.classList.contains('index-php')) {
positionCalloutContainer(true)
}
});I’ve temporarily solved this by putting a conditional around those blocks of:
if(document.getElementById("toplevel_page_sb-instagram-feed")){
...
}This whole thing is odd to me, however, as it seems like this script shouldn’t even be loading on the front-end of the website? This appears to be an admin-side script, no? Did a recent change accidentally make this script load on front-end as well?
- You must be logged in to reply to this topic.