Repository navigation
Conversation
…their `rendered` properties. WP_REST_Blocks_Controller removes `title.rendered` and `content.rendered` from the synced pattern schema, because a block only renders in the context of a post or a page. WP_REST_Posts_Controller::prepare_item_for_response() rendered both anyway, running `the_title` and `the_content` on every pattern REST response, only for filter_response_by_context() to discard the results. With hooks on `the_content`, that is wasted work on a hot editor path. Only run the rendering passes when the schema actually contains the `rendered` property, so schemas that keep the property are unaffected. Fixes #66644.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
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. |
Trac ticket: https://core.trac.wordpress.org/ticket/66644
Summary
WP_REST_Blocks_Controllerremovestitle.renderedandcontent.renderedfrom the synced pattern schema, because a block only renders in the context of a post or a page — butWP_REST_Posts_Controller::prepare_item_for_response()still ranget_the_title()andapply_filters( 'the_content' )on every pattern REST response, andfilter_response_by_context()then discarded the results. With hooks onthe_content, every pattern fetch in the site editor pays for a full render that is thrown away.Fix
Only run the
titleandcontentrendering passes when the controller's schema actually contains therenderedproperty. Controllers that keep the property — posts, pages, attachments, revisions, templates — take the exact same code path as before; the guards only skip work whose result the response would discard.Testing
New test
REST_Blocks_Controller_Test::test_rendered_fields_are_not_rendered()registers counters onthe_contentandthe_title, fetches a synced pattern over REST, and asserts neither filter ran.the_contentruns once for the discardedcontent.rendered.vendor/bin/phpunit --group restapi→ 4025 tests, 0 failures.vendor/bin/phpunit -c tests/phpunit/multisite.xml --group restapi-blocks→ OK.Use of AI Tools
AI assistance: Kimi (Moonshot AI) drafted the patch and the test; I reviewed every change, reproduced the issue on trunk, and ran and verified all results myself.