WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#12415 closed defect (bug) (worksforme)

wp_enqueue_style doesn't observe proper dependency order

Reported by: mtekk Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: General Keywords: needs-patch
Focuses: Cc:

Description

Since load-styles.php blindly loads styles in the order they are requested from it, it is vital that these are requested in the proper order. If someone calls

wp_enqueue_style('media');

wp_enqueue_style will produce the following dependency load:

load-styles.php?c=1&dir=ltr&load=media,global,wp-admin

This is bad as media depends on global and wp-admin, and must be loaded after global and wp-admin. Otherwise the cascading nature of CSS causes media's styles to do nothing. It should produce something like:

load-styles.php?c=1&dir=ltr&load=global,wp-admin,media

This actually looks to be an issue with WP_Dependencies, possibly broken logic in WP_Dependencies::all_deps, though I'm not sure if this is the case as wp_enqueue_scripts doesn't seem to be broken. This behavior was observed in r13462.

Change History (4)

comment:1 mtekk4 years ago

  • Summary changed from wp_enqueue_style doesn't obeserve proper dependency order to wp_enqueue_style doesn't observe proper dependency order

comment:2 follow-up: nacin4 years ago

CSS files don't have "dependencies". Nor would the media styles do nothing, just some rules may be overridden by global or wp-admin for any rules in media were designed to override global or wp-admin.

You should call CSS files in the order you want them, I'm not sure we can create a specific dependency hierarchy. It's not like jquery, where to run all scripts that use jquery, we need to make sure jquery is first.

comment:3 in reply to: ↑ 2 mtekk4 years ago

Replying to nacin:

CSS files don't have "dependencies". Nor would the media styles do nothing, just some rules may be overridden by global or wp-admin for any rules in media were designed to override global or wp-admin.

Yeah, media doesn't do "nothing" but many of the values it is supposed to override from global and wp-admin don't get set :), which defeats its usefulness in some situations.

You should call CSS files in the order you want them...

That's what I'm doing at the moment. It looks like the top code should have only output:

load-styles.php?c=1&dir=ltr&load=media

but something later added in global and wp-admin (caused a misdiagnosis of the cause).

I guess this ticket could be closed, and a new one opened as a feature request to have a dependency hierarchy for the styles. This already seems to be allowed when including an external style, would be nice to do it with default styles as well (the parameter in wp_enqueue_style doesn't seem to work for default styles).

comment:4 nacin4 years ago

  • Milestone 3.0 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Per:

I guess this ticket could be closed, and a new one opened as a feature request to have a dependency hierarchy for the styles.

Note: See TracTickets for help on using tickets.