{"id":19031437,"date":"2026-09-28T15:48:24","date_gmt":"2026-09-28T15:48:24","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/js-typeerror-in-live-refresh-data-content-is-used-after-checking-data-html-js\/"},"modified":"2026-09-28T15:48:24","modified_gmt":"2026-09-28T15:48:24","slug":"js-typeerror-in-live-refresh-data-content-is-used-after-checking-data-html-js","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/js-typeerror-in-live-refresh-data-content-is-used-after-checking-data-html-js\/","title":{"rendered":"JS TypeError in live refresh: data.content is used after checking data.html (js."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Environment<\/strong><\/p>\n\n\n\n<ul>\n<li>We&#8217;re Open! 2.6<\/li>\n\n\n\n<li>WordPress 7.1.2, PHP 8.2<\/li>\n\n\n\n<li>Opening hours output with live update enabled (elements with the class <code>.opening-hours.update<\/code>)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What happens<\/strong><br \/>After the page has loaded, the plugin sends its AJAX refresh (<code>action: we_are_open_wp_ajax<\/code>). When the response arrives, the browser console shows:TypeError: Cannot read properties of null (reading &#8216;replace&#8217;) at HTMLTableElement.&lt;anonymous&gt; (opening-hours\/wp\/js\/js.js) at jQuery.each \u2026 at Object.success (opening-hours\/wp\/js\/js.js)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the error, the rest of the refresh loop doesn&#8217;t run, so the opening hours are no longer updated live on that page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Cause<\/strong><br \/>In wp\/js\/js.js, inside the <code>success<\/code> callback of the <code>update<\/code> action (around line 210), the condition checks the wrong property before calling <code>.replace()<\/code>:content: (typeof data.html == &#8216;string&#8217;) ? data.content.replace(\/\\\\(\\&#8217;)\/gi, &#8216;$1&#8217;) : null,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the response element has <code>html<\/code> set but <code>content<\/code> is <code>null<\/code>, then <code>data.content.replace()<\/code> throws.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Suggested fix<\/strong><br \/>Check the property that is actually used:content: (typeof data.content == &#8216;string&#8217;) ? data.content.replace(\/\\\\(\\&#8217;)\/gi, &#8216;$1&#8217;) : null,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 <code>js.js<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for the plugin!<\/p>\n","protected":false},"template":"","class_list":["post-19031437","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19031437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19031437\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19031437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}