Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#53638 closed defect (bug) (worksforme)

Duplicate inline JS

Reported by: malthert's profile malthert Owned by:
Milestone: Priority: normal
Severity: blocker Version: 5.8
Component: Script Loader Keywords:
Focuses: Cc:


in /wp-includes/class.wp-scripts.php

public function __construct() {
    add_action( 'init', array( $this, 'init' ), 0 );

calls the init twice which leads to include the script twice as action

do_action_ref_array( 'wp_default_scripts', array( &$this ) );

Which then ends up with

<script id='lodash-js-after'>
window.lodash = _.noConflict();
window.lodash = _.noConflict();

on frontend.

This affects all scripts that use add inline script, basically bloating the frontend.

Change History (5)

#1 @malthert
3 years ago

Update: it's not only bloating the frontend, in some cases (like the above example) it will cause js console errors making the site unusable

#2 @desrosj
3 years ago

  • Keywords reporter-feedback added

Hi @malthert,

I have not been able to reproduce the behavior you are describing.

Do you have any plugins active? Are you testing on a default theme? Are there any steps someone needs to take in order to see this happening?

#3 @SergeyBiryukov
3 years ago

This could probably use a comment explaining the reason for double initialization.

Some history here:

#4 @malthert
3 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Issue fixed itself now. Problem was something else, but I can't remember what exactly.

#5 @desrosj
3 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution changed from invalid to worksforme
Note: See TracTickets for help on using tickets.