Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#54790 closed defect (bug) (fixed)

Stylesheets enqueued via `wp_enqueue_block_style` should only be enqueued when the block gets rendered

Reported by: aristath's profile aristath Owned by: hellofromtonya's profile hellofromTonya
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.9
Component: Editor Keywords: has-patch dev-reviewed commit fixed-major
Focuses: Cc:

Description

The issue was originally reported in https://make.wordpress.org/core/2021/12/15/using-multiple-stylesheets-per-block/#comment-42320 and a patch in Gutenberg exists in https://github.com/WordPress/gutenberg/pull/37848

In a block theme, styles for blocks only get printed when the block exists on a page. However, additional stylesheets enqueued via wp_enqueue_block_style always get printed.

More info and testing instructions can be found in the Gutenberg PR on https://github.com/WordPress/gutenberg/pull/37848

Change History (12)

This ticket was mentioned in PR #2138 on WordPress/wordpress-develop by aristath.


3 years ago
#1

  • Keywords has-patch added

When using a block theme, make sure that additional block styles enqueued using wp_enqueue_block_style only get printed when the block exists on the page.

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

#2 @Mamaduka
3 years ago

I've tested this patch in the Gutenberg repo, and it works as expected - https://github.com/WordPress/gutenberg/pull/37848#pullrequestreview-849055787.

#3 @aristath
3 years ago

Thank you for testing and confirming the fix @Mamaduka!
The PR in Gutenberg was merged, so this is now a backport fix for 5.9 :)

#4 @hellofromTonya
3 years ago

  • Component changed from General to Editor
  • Keywords commit added
  • Milestone changed from Awaiting Review to 5.9

As this is a backport from Gutenberg and was reported in RC1, moving into 5.9 for RC2 and marking for commit.

#5 @hellofromTonya
3 years ago

  • Owner set to hellofromTonya
  • Status changed from new to reviewing

Self-assigning for trunk commit.

#7 @hellofromTonya
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

Whoopsie [52556] had the wrong ticket number :facepalm:. Manually adding it here.

In 52556:

Editor: Fix enqueueing additional styles in wp_enqueue_block_style() to print only when blocks render.

In a block theme, additional block styles registered using the wp_enqueue_block_style function should only get printed when the block exists on a page. However, they currently always get rendered.

This commit is a backport from Gutenberg that fixes the issue by printing the styles when a block renders.

Follow-up to [52069].

Props poena, aristath, Mamaduka.
Fixes #54787.

#8 @hellofromTonya
3 years ago

  • Keywords dev-feedback added; commit removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-opening for second committer review to backport to 5.9-branch for RC2.

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


3 years ago

#10 @audrasjb
3 years ago

  • Keywords dev-reviewed commit fixed-major added; dev-feedback removed

I agree with the statement concerning anonymous functions, but let's commit this for now. It would be nice to adjust this in 6.0 though.

Marking as dev-reviewed.

#11 @hellofromTonya
3 years ago

Thanks @audrasjb. Prepping the backport commit now.

#12 @hellofromTonya
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Consistent with the wrong ticket number :facepalm:

In 52559:

Editor: Fix enqueueing additional styles in wp_enqueue_block_style() to print only when blocks render.

In a block theme, additional block styles registered using the wp_enqueue_block_style function should only get printed when the block exists on a page. However, they currently always get rendered.

This commit is a backport from Gutenberg that fixes the issue by printing the styles when a block renders.

Follow-up to [52069].

Props poena, aristath, Mamaduka.
Merges [52556] to the 5.9 branch.
Fixes #54787.

Note: See TracTickets for help on using tickets.