Make WordPress Core

Opened 15 months ago

Closed 4 weeks ago

#63908 closed defect (bug) (invalid)

Style concatenation may duplicate inline styles

Reported by: jonsurrell Owned by:
Priority: normal Milestone:
Component: Script Loader Version:
Severity: normal Keywords:
Cc: Focuses: css

Description

When styles are concatenated with /wp-admin/load-styles.php in multiple batches, inline styles are duplicated across batches.

For example, with this snippet adds inline styles to some core styles:

<?php
add_action(
        'wp_default_styles',
        function ( $s ) {
                wp_add_inline_style( 'revisions', 'wp-example { content: "inline:revisions" }' );
                wp_add_inline_style( 'dashicons', 'wp-example { content: "inline:dashicons" }' );
                wp_add_inline_style( 'editor-buttons', 'wp-example { content: "inline:editor-buttons" }' );
                return $s;
        }
);

I visit /wp-admin/customize.php with the Twenty Twenty theme and SCRIPT_DEBUG set to false (script concatenation is enabled).

Multiple concatenated styles are used. First is a concatenation using wp-admin/load-styles.php for these styles:

dashicons, common, forms, admin-menu, dashboard, list-tables,
edit, revisions, media, themes, about, nav-menus, wp-pointer,
widgets, site-icon, l10n, buttons, customize-controls,
customize-widgets, wp-block-library, classic-theme-styles,
wp-components, wp-widgets, wp-preferences, wp-block-editor,
wp-reusable-blocks, wp-patterns, wp-editor, wp-reset-editor-styles,
wp-block-editor-content, wp-editor-classic-layout-styles,
wp-edit-blocks, wp-customize-widgets, wp-block-directory,
wp-format-library, customize-nav-menus, media-views,
wp-color-picker, code-editor
<link rel='stylesheet' href='…' media='all' />
<style>
wp-example { content: "inline:dashicons" }wp-example { content: "inline:revisions" }
</style>

The inline styles associated with the styles are output after the stylesheet link.

Later, there is another concatenated styles, oddly this is _only_ for editor-buttons:

<link rel='stylesheet' href='…' media='all' />
<style>
wp-example { content: "inline:dashicons" }wp-example { content: "inline:revisions" }wp-example { content: "inline:editor-buttons" }
</style>

Notice that the inline styles from the previous concatenated script is included here, plus the additional editor-buttons inline style.

The concatenated inline styles should not be repeated in this block.

Even if editor-button does not have inline styles, the original concatenated inline styles will be output again after the editor-buttons concatenated style link.

Change History (3)

#1 @westonruter
15 months ago

This would be fixed by eliminating concatenation: #57548

#2 @westonruter
4 weeks ago

In 64585:

Script Loader: Retire script and style concatenation.

Scripts and styles in the admin and on the login screen are no longer concatenated through load-scripts.php and load-styles.php. Concatenation paid off when browsers opened few connections per host over HTTP/1.1, but it has long been a source of bugs: dependencies outside the default directories were not honored, SCRIPT_DEBUG and the script_loader_src and style_loader_src filters were ignored, inline styles could be duplicated, and code run by the loaders without WordPress loaded caused fatal errors. It was turned off by default in r64320, once the assets of the next admin screen began to be prefetched in r64120, and this removes what remains.

Every item is now printed as its own tag, and what remains of the concatenation API is deprecated or removed:

  • The properties of WP_Scripts and WP_Styles that held items back for concatenation are deprecated but still declared, so plugins reading or setting them keep working. The do_item() methods no longer check do_concat.
  • The _print_scripts(), _print_styles(), script_concat_settings(), in_default_dir() and WP_Dependencies::get_etag() functions are deprecated.
  • The print_head_scripts, print_footer_scripts, print_admin_styles and print_late_styles filters only decided whether held markup was printed, so they are applied with apply_filters_deprecated() and their return values are ignored.
  • The CONCATENATE_SCRIPTS constant is no longer read.
  • The wp_should_concatenate_admin_scripts() function and its filter, added in r64120 for the transition and never released, are removed.

The loaders now respond with 410 Gone and a one-line plain text explanation, without loading WordPress, so that requests from bots and stale links cost next to nothing. Code written to run inside them without WordPress loaded, such as wp_theme_has_theme_json(), now uses the functions it had avoided, and wp-admin/includes/noop.php no longer defines its stub functions.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14463.
Follow-up to r10357, r43580, r60719, r62657, r64120, r64320, r64485.

Props westonruter, jonsurrell, peterwilsoncc, azaozz, markhowellsmead, sergiomdgomes, jerclarke, adamsilverstein, sukhendu2002, adnan007, momo360modena, desrosj, welcher.
See #15833, #36448, #36449, #36779, #43825, #45008, #47322, #52879, #63908, #64087, #65515.
Fixes #57548.

#3 @westonruter
4 weeks ago

  • Milestone Awaiting Review
  • Resolution → invalid
  • Status new → closed

Closing as obsolete now that script concatenation has been retired in #57548.

Note: See TracTickets for help on using tickets.