[wp-trac] [WordPress Trac] #60111: Twenty Twenty-One: Dark mode toggle script loaded twice in frontend

WordPress Trac noreply at wordpress.org
Thu Feb 15 05:41:48 UTC 2024


#60111: Twenty Twenty-One: Dark mode toggle script loaded twice in frontend
---------------------------+------------------------------
 Reporter:  flixos90       |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Bundled Theme  |     Version:  6.4
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |     Focuses:
---------------------------+------------------------------

Comment (by zlvkrxjv47):

 It appears that there is an issue with the Twenty Twenty-One theme where
 the dark mode toggle script (`dark-mode-toggler.js`) is being loaded twice
 in the frontend, and the editor-specific script (`editor-dark-mode-
 support.js`) is also being loaded unnecessarily.

 This issue seems to have been introduced by changes made in revision
 [56300], which modified the hook to support the editor iframe. However,
 this change may not have considered the unintended consequence of loading
 editor-specific scripts in the frontend as well.

 To address this issue:

 1. **Remove Redundant Loading**: Since the contents of `dark-mode-
 toggler.js` are already inlined for the frontend, there is no need to
 enqueue it. Remove any enqueueing of `dark-mode-toggler.js` for the
 frontend.

 2. **Exclude Editor-Specific Scripts**: Ensure that `editor-dark-mode-
 support.js` is not loaded in the frontend at all, as it is only relevant
 for the editor. This can be achieved by conditionally enqueueing the
 script only when needed, such as within the editor context.

 3. **Review Changes in [56300]**: Take a closer look at the changes made
 in revision [56300] to understand how the hook was modified to support the
 editor iframe. Determine if there was an oversight regarding the loading
 of editor-specific scripts in the frontend.

 4. **Test the Changes**: After making the necessary adjustments,
 thoroughly test the frontend to confirm that the dark mode toggle
 functionality still works as expected and that the editor-specific script
 is no longer loaded unnecessarily.

 By addressing these points, you can resolve the issue of the dark mode
 toggle script being loaded twice in the frontend and prevent the loading
 of editor-specific scripts where they are not needed, thereby improving
 the efficiency and performance of the Twenty Twenty-One theme.

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


More information about the wp-trac mailing list