WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 4 weeks ago

Last modified 3 weeks ago

#53638 closed defect (bug) (worksforme)

Duplicate inline JS

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

Description

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

public function __construct() {
    $this->init();
    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();
</script>

on frontend.

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

Change History (5)

#1 @malthert
3 months 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
2 months 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
2 months ago

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

Some history here:

#4 @malthert
4 weeks 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 weeks ago

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