[wp-trac] [WordPress Trac] #56969: decoding="async" breaks my site

WordPress Trac noreply at wordpress.org
Fri Nov 4 00:07:32 UTC 2022


#56969: decoding="async" breaks my site
-------------------------------+------------------------------
 Reporter:  rodricus           |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Media              |     Version:  6.1
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:  performance
-------------------------------+------------------------------

Comment (by joelmadigan):

 I'd like to chime in with an instance of the same issue in a slightly
 different context.

 In my case, NinjaForms apparently uses JSON+JavaScript to load their forms
 and the method used by WordPress to inject the decode="async" attribute
 doesn't take the image possibly being in a double-quoted string into
 account.

 {{{
 {
   "objectType": "Field",
   "objectDomain": "fields",
   "editActive": false,
   "order": 14,
   "idAttribute": "id",
   "label": "HTML",
   "type": "html",
   "default": "<p><img decoding="async " style=\"width: 604px;\"
 src=\"https:\/\/www.lewislandscape.com\/wp-
 content\/uploads\/2022\/05\/CheckImage.png\"><br><\/p>",
   "container_class": "",
   "element_class": "",
   "key": "html_1652099495998",
   "drawerDisabled": false,
   "id": 28,
   "beforeField": "",
   "afterField": "",
   "value": "<p><img decoding="async " style=\"width: 604px;\"
 src=\"https:\/\/www.lewislandscape.com\/wp-
 content\/uploads\/2022\/05\/CheckImage.png\"><br><\/p>",
   "label_pos": "above",
   "parentType": "html",
   "element_templates": ["html", "input"],
   "old_classname": "",
   "wrap_template": "wrap"
 },
 }}}

 As we can see in this snippet, "default" and "value" have the string
 terminated early causing the JavaScript parser to abend with Unexpected
 Keyword: async.

 I fixed it with
 {{{#!php
 <?php
 add_filter('wp_img_tag_add_decoding_attr', '__return_false');
 }}}
 in theme functions.php, but it's not ideal.

 I suspect this could be fixed by escaping the double quotes (for the lazy
 loading injection too), which shouldn't bother the HTML parser.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56969#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list