JS TypeError in live refresh: data.content is used after checking data.html (js.
-
Environment
- We’re Open! 2.6
- WordPress 7.1.2, PHP 8.2
- Opening hours output with live update enabled (elements with the class
.opening-hours.update)
What happens
After the page has loaded, the plugin sends its AJAX refresh (action: we_are_open_wp_ajax). When the response arrives, the browser console shows:TypeError: Cannot read properties of null (reading ‘replace’) at HTMLTableElement.<anonymous> (opening-hours/wp/js/js.js) at jQuery.each … at Object.success (opening-hours/wp/js/js.js)After the error, the rest of the refresh loop doesn’t run, so the opening hours are no longer updated live on that page.
Cause
In wp/js/js.js, inside thesuccesscallback of theupdateaction (around line 210), the condition checks the wrong property before calling.replace():content: (typeof data.html == ‘string’) ? data.content.replace(/\\(\’)/gi, ‘$1’) : null,If the response element has
htmlset butcontentisnull, thendata.content.replace()throws.Suggested fix
Check the property that is actually used:content: (typeof data.content == ‘string’) ? data.content.replace(/\\(\’)/gi, ‘$1’) : null,With this one-line change the error is gone and the refresh works as expected. We verified this on our site by serving a patched copy of
js.js.Thanks for the plugin!
You must be logged in to reply to this topic.