Block Supports: Prevent Additional CSS duplication inside Query Loop#12117
Block Supports: Prevent Additional CSS duplication inside Query Loop#12117Anupkankale wants to merge 2 commits into
Conversation
When a block inside a Query Loop has Additional CSS, wp_add_inline_style was called once per post in the loop, duplicating the same CSS N times. This was because wp_unique_id_from_values produces the same hash for the same block data on every loop iteration. This fix adds a static $enqueued_class_names array to track already-enqueued class names so subsequent loop iterations skip the redundant wp_add_inline_style call. Props mustafabharmal, westonruter. Fixes #65268.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Replaced the static variable cache with a check against the global $wp_styles object. This ensures that the deduplication logic stays in sync with the styles system and correctly handles test environment resets where $wp_styles is re-initialized between tests. Props mustafabharmal, westonruter. See #65268.
|
Thank you for the PR. However, we already have an ongoing PR for this: #11859 |
When a block inside a Query Loop has Additional CSS, wp_add_inline_style was called once per post in the loop, duplicating the same CSS N times. This was because wp_unique_id_from_values produces the same hash for the same block data on every loop iteration.
This fix adds a static $enqueued_class_names array to track already-enqueued class names so subsequent loop iterations skip the redundant wp_add_inline_style call.
Props mustafabharmal, westonruter.
Fixes #65268.
Trac ticket:
Use of AI Tools
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.