[wp-trac] [WordPress Trac] #55491: Replace `unload` event handlers from core

WordPress Trac noreply at wordpress.org
Thu Aug 24 18:43:56 UTC 2023


#55491: Replace `unload` event handlers from core
-------------------------------------+-------------------------------------
 Reporter:  shawfactor               |       Owner:  westonruter
     Type:  enhancement              |      Status:  accepted
 Priority:  normal                   |   Milestone:  6.4
Component:  Administration           |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  good-first-bug has-      |     Focuses:  javascript,
  patch                              |  performance
-------------------------------------+-------------------------------------

Comment (by westonruter):

 One of the instances of `unload` is coming from the TinyMCE vendor
 dependency,
 [https://core.trac.wordpress.org/browser/trunk/src/js/_enqueues/vendor/tinymce/tinymce.js#L1254
 src/js/_enqueues/vendor/tinymce/tinymce.js]:

 {{{#!js
       if (parent && parent !== getTop(parent)) {
         if (parent.addEventListener) {
           parent.addEventListener('unload', function () {
             setDocument();
           }, false);
         } else if (parent.attachEvent) {
           parent.attachEvent('onunload', function () {
             setDocument();
           });
         }
       }
 }}}

 To fix this, we'd have to patch TinyMCE in wordpress-develop, as the
 current version 4.9.11 was released on 2020-07-13 which seems to be the
 last 4.x release. Not sure whether TinyMCE would do another 4.x release to
 fix the issue. This `tinymce.js` file is loaded in both the Classic Editor
 and the Block Editor, although Gutenberg has an experiment to discontinue
 loading TinyMCE by default.

 The source of this code can be found in the TinyMCE repo, specifically
 [https://github.com/tinymce/tinymce/blob/d79205cbe7d9f74e2ca287ee4e7dee3c32138b5b/src/core/main/ts/api/dom/Sizzle.ts#L505-L520
 from the Sizzle library]:

 {{{#!js
   // Support: IE>8
   // If iframe document is assigned to "document" variable and if iframe
 has been reloaded,
   // IE will throw "permission denied" error when accessing "document"
 variable, see jQuery #13936
   // IE6-8 do not support the defaultView property so parent will be
 undefined
   if (parent && parent !== getTop(parent)) {
     // IE11 does not have attachEvent, so all must suffer
     if (parent.addEventListener) {
       parent.addEventListener('unload', function () {
         setDocument();
       }, false);
     } else if (parent.attachEvent) {
       parent.attachEvent('onunload', function () {
         setDocument();
       });
     }
   }
 }}}

 So the code is specifically in place for Internet Explorer, which
 WordPress no longer supports. Therefore, it seems this code should could
 be removed entirely. Nevertheless, it is also present in the
 [https://github.com/jquery/sizzle/blob/4194dc464e7381139220e39ceb46c0bdfe12dd59/src/sizzle.js#L624-L641
 most recent version of Sizzle], and it specifically calls out Edge:

 {{{#!js
         // Support: IE 9 - 11+, Edge 12 - 18+
         // Accessing iframe documents after unload throws "permission
 denied" errors (jQuery #13936)
         // Support: IE 11+, Edge 17 - 18+
         // IE/Edge sometimes throw a "Permission denied" error when
 strict-comparing
         // two documents; shallow comparisons work.
 }}}

 But seems that this is not actually relevant to Edge using Chromium, which
 it has since 2018. The highest version of Edge referenced in the
 [https://github.com/jquery/sizzle/commit/cd0239bf326397cd5cf93438532436c235bf2bb0
 last change] is Edge 18+ (cf.
 [https://github.com/jquery/sizzle/commit/3b1abbab1fb0c8080f36ad889d37704c7be13641
 first Edge mention commit]), and Edge started using Chromium in v79. So it
 does seem obsolete.

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


More information about the wp-trac mailing list