Repository navigation
Conversation
Ship a generated file with the SVG markup of the icons in the core-admin collection, and use it in the icons registry so that these icons are not read from disk and sanitized on every admin request. Backports WordPress/gutenberg#84552.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Backports WordPress/gutenberg#84552. Ships a generated PHP file with the SVG markup of the
core-adminicons, and makes the icons registry use it.Why?
#12270 replaces the Dashicons in the admin menu and admin bar with
core-admin/*icons. Every admin page then reads about 20 SVG files from disk and runswp_kses()on each of them, a cost the CSS-based Dashicons never had. This was raised in review.These icons ship with core, so their markup is trusted and only changes with a release. Inlining it removes both the file reads and the sanitization.
How?
src/wp-includes/assets/icon-library-inlined-icons.phpmaps eachcore-admin/*icon name to its SVG markup. It is generated in Gutenberg and copied by a newcopy:icon-library-inlined-iconsstep inbuild:gutenberg, next to the icon manifest.WP_Icons_Registry::get_content()returns the inlined markup when the icon name is in that file and itsfile_pathis insidewp-includes/images/icon-library/. An icon registered under the same name from another location still has its file read and sanitized.The inlined markup is the file content with the whitespace between tags removed. Compared to the sanitized output it keeps
viewBoxin its original casing;wp_kses()lowercases it.In a local Docker environment without opcache, on top of #12270, this takes the first render of the 20 admin icons from about 6 ms to about 1 ms. This is a micro-benchmark of the icon calls, not a page load profile.
Testing Instructions
Run
npm run test:php -- --group icons. The new tests check that every inlined icon exists in the manifest, that its markup is equivalent to its sanitized file, and that the registry serves it.Draft notes:
inlined-icons.phpyet, so the committed file was produced by running the Gutenberg generator against the currently pinned icons. Until the pin moves past Icons: Inline the markup of core-admin icons gutenberg#84552, the new copy step has nothing to copy and leaves the file as is.trunk, so CI is their first run here.Trac ticket: TBD
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: Implementation, tests and this description; reviewed by me.
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.