Repository navigation
perf: load icon sets only when the picker is used, cache single icons, fix tabler - #185
Merged
Merged
Conversation
bs_render_icon() wrote the complete decoded set (up to 5 MB for simple-icons) into a 30 day transient on the first render of any icon, which lands in wp_options without a persistent object cache. Only the rendered icon is cached now, and a set file is decoded at most once per request. Set transients left by earlier versions expire within 30 days and are removed by the daily delete_expired_transients event.
Every icon field mounted fetched its whole set from /blockstudio/v1/icons (up to 5 MB of SVG markup) and kept it in the store, although the SVGs are only rendered once the dropdown is open. The set is now requested on the first focus of the picker or when the set or sub set is changed. A closed field lists just the stored icon, the combobox shows its loading state while the set arrives, and a failed request no longer leaves the field without a picker. The REST response is unchanged.
The picker requested the set tabler-icons, but the files are tabler-icons-outline.json and tabler-icons-filled.json, so tabler never showed up. The sub sets are listed as in the files. Switching to a set whose sub sets do not include solid also kept solid as the sub set and requested a file that does not exist (remix-icons.json). The sub set now follows the set, preferring a configured one, then solid, then the first.
This was referenced Oct 24, 2026
Collaborator
Author
|
E2E check with the Playground runner from #189, this branch merged onto main and built: |
Contributor
|
Released in Blockstudio 7.7.9. Thanks for the contribution. |
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.
Related to #8 (the ZIP size itself is not addressed here).
The icon field loaded and stored far more than it needs.
Frontend:
bs_render_icon()stored the complete decoded set as a 30 day transient on the first render of any icon. Without a persistent object cache that is a row of up to 5 MB inwp_options(1,289,328 B for fontawesome-free solid, 5,055,377 B for simple-icons) next to the per-icon row. Only the rendered icon is cached now (369 B and 838 B written on a first render), and a set file is decoded at most once per request. Set transients written by earlier versions expire within 30 days and are then removed by the dailydelete_expired_transientsevent, so there is no migration. Render output and the stored value{set, subSet?, icon}are unchanged.Editor: every icon field fetched its whole set from
/blockstudio/v1/iconsas soon as the block was selected (1.3 MB for fontawesome-free solid, 5.1 MB for simple-icons, 2.8 MB for tabler outline), although the SVGs only render once the dropdown opens. The set is now requested on first focus of the picker or when the set or sub set changes. A closed field lists the stored icon, the combobox shows its spinner while the set loads, and a failed request no longer leaves the field without a picker. The REST response is unchanged. Selecting a block with two icon fields went from two requests (about 1.7 MB) to none; opening the picker fetches one set and lists the same 1,984 options with the same previews.Tabler: the picker requested
set=tabler-icons, but the files aretabler-icons-outline.jsonandtabler-icons-filled.json, so the request failed and tabler never showed up. The sub sets are now listed as in the files. The default sub set was alwayssolid(thefontawesome-freecheck is always true), which remix-icons, material-design-icons and tabler do not have, so switching to those sets requested a missing file. The default now follows the set: a configured sub set the set has, thensolid, then its first one.Tests: PHPUnit for
bs_render_icon()(no set transient, per-icon transient written and served, missing set and icon silent; two cases fail against the old code), client tests for the picker options and for the set map against the files inincludes/icons(fail with the old tabler entry), and two cases in the icon E2E. Measured in WordPress Playground (WordPress 7.1, PHP 8.4); the E2E cases were not run locally (no Docker), the same flows were checked by hand in the editor there.npm run checkpasses.