Make WordPress Core

Opened 4 years ago

Last modified 3 weeks ago

#51837 reviewing defect (bug)

Adding `add_theme_support` for html5 for scripts, does not remove the type attribute from `wp-emoji-release.min.js`

Reported by: kanlukasz's profile kanlukasz Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version: 5.3
Component: Script Loader Keywords: has-patch
Focuses: Cc:

Description

This is a follow-up to #42804.

Using: add_theme_support('html5', ['script', 'style']); removes the type attribute from my custom scripts but does not remove it from the default wp-emoji-release.min.js

Eg.:
<script src="https://example.com/wp-includes/js/wp-emoji-release.min.js?ver=5.5.3" type="text/javascript" defer=""></script>

Attachments (3)

51837.diff (5.0 KB) - added by tferry 4 years ago.
Removes the type attribute from emoji scripts and zxcvbn-async.js when theme supports html5 script tags
51837.2.diff (3.8 KB) - added by tferry 4 years ago.
Updated patch without changes to the package-lock.json file
51837.3.diff (3.6 KB) - added by tferry 4 years ago.
Removes emoji_type_attr filter

Download all attachments as: .zip

Change History (15)

#1 @peterwilsoncc
4 years ago

  • Version changed from 5.5.3 to 5.3

Hello @kanlukasz and welcome to trac!

I've been able to confirm the report, the script is loaded using JavaScript in emoji-loader.js and the theme support setting is not passed to the JavaScript to determine if the type attribute should be included.

From /src/js/_enqueues/lib/emoji-loader.js:

function addScript( src ) {
        var script = document.createElement( 'script' );

        script.src = src;
        script.defer = script.type = 'text/javascript';
        document.getElementsByTagName( 'head' )[0].appendChild( script );
}

At a quick glance the same issue applies to src/js/_enqueues/lib/zxcvbn-async.js if it's loaded on the front-end of a site. Some external libraries may include the type too but unfortunately they are out of WordPress's control.

@tferry
4 years ago

Removes the type attribute from emoji scripts and zxcvbn-async.js when theme supports html5 script tags

#2 @SergeyBiryukov
4 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 5.8
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Thanks for the patch! I don't think the emoji_type_attr filter is needed here, just checking current_theme_supports( 'html5', 'script' ) should be enough. Looks good to me otherwise.

@tferry
4 years ago

Updated patch without changes to the package-lock.json file

#3 @tferry
4 years ago

Thanks @SergeyBiryukov! I've also refreshed the patch to remove the changes to the package-lock.json file - not sure how that snuck in...

@tferry
4 years ago

Removes emoji_type_attr filter

This ticket was mentioned in Slack in #core by chaion07. View the logs.


3 years ago

#5 @chaion07
3 years ago

Thanks to @kanlukasz for reporting this issue. We reviewed this ticket during a recent [bug-scrub session]https://wordpress.slack.com/archives/C02RQBWTW/p1623096832360300. With Beta 1 coming in a day, checking with @SergeyBiryukov to kindly draw some attention to this. Thank you!

#6 @hellofromTonya
3 years ago

  • Milestone changed from 5.8 to 5.9

Today is 5.8 Beta 1. Ran out of time to land this one. Looks really close to ready pending code review. Punting to 5.9.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


3 years ago

#8 @audrasjb
3 years ago

  • Milestone changed from 5.9 to 6.0

As per today's bug scrub, let's move this ticket to the next milestone for proper review/refresh.

This ticket was mentioned in Slack in #core by mike. View the logs.


3 years ago

#10 @costdev
3 years ago

  • Keywords needs-refresh added

Per the discussion in the bug scrub, I'm adding needs-refresh as patch 51837.3.diff no longer applies cleanly against trunk.

#11 @costdev
3 years ago

  • Milestone changed from 6.0 to Future Release

With 6.0 RC1 tomorrow, I'm moving this ticket to the Future Release milestone.

This ticket was mentioned in PR #7787 on WordPress/wordpress-develop by @sukhendu2002.


3 weeks ago
#12

  • Keywords needs-refresh removed

Trac ticket: https://core.trac.wordpress.org/ticket/51837

This PR addresses the issue where the type="text/javascript" attribute is not removed from the default WordPress scripts wp-emoji-release.min.js and zxcvbn.min.js when add_theme_support('html5', ['script', 'style']); is enabled. The add_theme_support function removes the type attribute from custom scripts, but not from these default WordPress scripts.

Note: See TracTickets for help on using tickets.