Repository navigation
Conversation
|
Size Change: 0 B Total Size: 7.61 MB |
…brary Proof of concept. Read the list of block types from the core /wp/v2/block-types endpoint through @wordpress/core-data, instead of loading @wordpress/block-library and calling registerCoreBlocks() just to enumerate the blocks that can carry guidelines. - Add a `blockType` core-data root entity for /wp/v2/block-types (entity.ts). - Rewrite useContentBlocks() to read that entity and filter content blocks from the REST shape (data.ts). - Delete bootstrap-block-registry.ts and drop the registerCoreBlocks() call. - Stop enqueuing the wp-block-library script on the page (load.php). - Drop @wordpress/block-library, @wordpress/blocks, and the lock-unlock helper. Trade-off: Core block icons are not in the REST response, so the Blocks list falls back to a generic icon. See the pull request description for the full pros and cons. Part of #77230 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
9fa9b23 to
445ddec
Compare
|
Flaky tests detected in 445ddec. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28437540244
|
|
@aagam-shah and @aaronjorbin, I have three observations based on this prototype:
|
@t-hamano, I'm looking at #75715. So that could potentially be a solution to register SVG icons on the server and set them as block icons consumed on the client. Is there any effort to offer a string to SVG conversion similar to Dashicons? To give an example, for the Paragraph block we do the following: import { paragraph as icon } from '@wordpress/icons';Could we instead set For custom icons, you would use |
I believe it is technically feasible. We could read the However, we are intentionally excluding them to prevent icons unrelated to post content from appearing in the Icon block picker. We are considering an option to register icons in the icon registry without making them insertable or selectable. See #77260 (comment) P.S. There is also a PR proposing to support file paths in the icon field of block.json. #79658 |
|
This does not seem actionable at the moment. |
What?
Part of #77230. Follow up to #79674.
This is a proof of concept, opened as a draft to illustrate an idea and gather feedback.
It changes the Guidelines screen so it reads the list of block types from the REST API (
/wp/v2/block-types) through@wordpress/core-data, instead of loading@wordpress/block-libraryand callingregisterCoreBlocks()only to enumerate blocks.Why?
The Guidelines screen has a Blocks section where you set guidelines per block. To build that list today, the page loads the whole block library (every Core block's editor code) just to read each block's name, title, icon, and whether it can carry content. That is a large bundle to load for what is, in effect, a list of names.
The REST API already exposes the registered block types, so the page can read the list as data. This also lines up with the long term goal of supporting more than Core blocks, since the endpoint returns every server-registered block.
How?
blockTypecore-datarootentity for/wp/v2/block-types. The page already registers a custom entity for guideline scopes, so this follows the same pattern.useContentBlocks()to read that entity withuseEntityRecordsand keep only content blocks. A content block has an attribute with thecontentrole, or supportscontentRole. This mirrors theisContentBlockprivate API from@wordpress/blocks, but reads the REST shape (the server normalizes the legacy__experimentalRoletorole).bootstrap-block-registry.tsand stop callingregisterCoreBlocks().wp-block-libraryscript on the page.@wordpress/block-library,@wordpress/blocks, and the lock-unlock helper from the route.Trade-offs (pros and cons)
Pros
@wordpress/block-library(the largest editor bundle) plus@wordpress/blocksand the lock-unlock helper from the page. It no longer parses and runs every Core block just to list names.wp-block-libraryscript enqueue from the PHP.bootstrap-block-registry.tsand thereapplyBlockTypeFilters()/registerCoreBlocks()step.useEntityRecords, the same way the page already loads scopes and rows.unlock( blocksPrivateApis ).isContentBlock.Cons
icon: nullfor Core blocks, because their SVG icons live in the JavaScript bundle. So the Blocks list and picker show a generic block icon. This is the main user-visible cost. (A third-party block that sets a dashicon inblock.jsonwould still show that dashicon.)attributes(that is where the content role lives), so even with_fieldsit carries every block's attribute schema. It is still smaller than the block-library bundle, and it is data rather than code, but it is a per-load transfer.isContentBlockTypere-implements the privateisContentBlock. They could drift. A clean follow up would be to add an object-takingisContentBlockType( blockType )export to@wordpress/blocksand reuse it.blocks.registerBlockTypefilter, would not be seen. On a standalone settings page with no editor this is effectively a non-issue, but it is a semantic difference./wp/v2/block-typesneedsedit_posts. The page ismanage_optionstoday, so administrators are fine. It would matter only if the page capability were ever lowered.Testing Instructions
npm install && npm run build.wp-block-libraryscript is no longer loaded, and that a request to/wp/v2/block-typesis made.Testing Instructions for Keyboard
Screenshots or screencast
The visible change is the block icon in the Blocks list: the real block icon before, a generic block icon after.
Use of AI Tools
This pull request was prepared with the help of Claude Code (Anthropic). The AI assisted with the data layer change, the REST content-role check, removing the block-library dependency, and this description. All changes are reviewed by the author. This is a draft proof of concept and has not yet been built or verified in a running site.