Skip to content

REST API: Skip rendering title and content when the schema omits their rendered properties - #15888

Open
dhrupo wants to merge 1 commit into
WordPress:trunkfrom
dhrupo:66644-rest-blocks-render
Open

dhrupo wants to merge 1 commit into
WordPress:trunkfrom
dhrupo:66644-rest-blocks-render

Conversation

@dhrupo

@dhrupo dhrupo commented Nov 10, 2026

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/66644

Summary

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 — but WP_REST_Posts_Controller::prepare_item_for_response() still ran get_the_title() and apply_filters( 'the_content' ) on every pattern REST response, and filter_response_by_context() then discarded the results. With hooks on the_content, every pattern fetch in the site editor pays for a full render that is thrown away.

Fix

Only run the title and content rendering passes when the controller's schema actually contains the rendered property. 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 on the_content and the_title, fetches a synced pattern over REST, and asserts neither filter ran.

  • Before: fails — the_content runs once for the discarded content.rendered.
  • After: passes; the full REST API suite is green.

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.

…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.
@github-actions

Copy link
Copy Markdown

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:

Props dhrupo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant