[wp-trac] [WordPress Trac] #65268: Block Supports: Prevent Additional CSS duplication inside Query Loop

WordPress Trac noreply at wordpress.org
Tue May 19 10:10:30 UTC 2026


#65268: Block Supports: Prevent Additional CSS duplication inside Query Loop
----------------------------+-----------------------------
 Reporter:  mustafabharmal  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  trunk
 Severity:  normal          |   Keywords:  has-patch
  Focuses:                  |
----------------------------+-----------------------------
 When using the Additional CSS feature on a block inside a Query Loop, the
 generated CSS is inserted once for every rendered post/item in the loop.
 This causes the same CSS rules to be duplicated N times in the page
 output.

 Root cause: `gutenberg_render_custom_css_support_styles` is hooked to
 `render_block_data`, which fires once per block render. Inside a Query
 Loop the same block template renders once per post, so
 `wp_add_inline_style` is called N times with the same CSS content.

 Since `wp_unique_id_from_values` produces the same hash for the same block
 data, each loop iteration generates the same `$class_name` and the same
 `$processed_css`.

 Fix: Use a static variable to track already-enqueued class names so
 subsequent loop iterations skip the redundant `wp_add_inline_style` call.

 Gutenberg issue: https://github.com/WordPress/gutenberg/issues/78278
 Gutenberg PR: https://github.com/WordPress/gutenberg/pull/78282

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65268>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list