Server-Timing: Reuse the WordPress 6.9 template enhancement output buffer#2515
Conversation
…buffer for Server-Timing. Instead of starting its own output buffer at template_redirect (and sending the header via the template_include filter when buffering is disabled), the Server-Timing API now relies on the template enhancement output buffer introduced in WordPress 6.9 (Core-43258, r60936): - When output buffering is enabled, the header is sent at the wp_finalized_template_enhancement_output_buffer action, which also opts in to starting the core output buffer. - When output buffering is disabled, the header is sent at the wp_before_include_template action. This removes the custom output buffer and its "register earliest to flush last" ordering hack. Requires the minimum WordPress version to be 6.9. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #2515 +/- ##
==========================================
+ Coverage 69.33% 69.38% +0.04%
==========================================
Files 90 90
Lines 7749 7714 -35
==========================================
- Hits 5373 5352 -21
+ Misses 2376 2362 -14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Reuses the WordPress 6.9 template enhancement output buffer (Core-43258, see r60936) for the Server-Timing header, instead of Performance Lab starting its own output buffer.
wp_finalized_template_enhancement_output_bufferaction — after the template has been captured and enhanced. Registering this action also opts in to starting the core output buffer (wp_should_output_buffer_template_for_enhancement()), and core runs thewp_template_enhancement_output_bufferfilter (used by Optimization Detective) before this action, so those metrics are captured before the header is sent.wp_before_include_templateaction, right before the template is included.This removes the custom output buffer (
start_output_buffer()), theon_template_include()filter callback, and the "register earliest so the callback flushes last" ordering hack. Net result is less code and no competing/nested output buffer when other consumers (e.g. Optimization Detective) are active.Fixes #2225.
Dependency
function_exists()guards. Please land after/with the 6.9 minimum-version bump.Known limitation
In the non-buffered path,
wp_before_include_templateonly fires when the resolved template is a readable file (unlike the oldtemplate_includefilter, which fired unconditionally). On routes where no readable template is included, the Server-Timing header is not sent. This is an accepted trade-off of reusing the core buffer.Test plan
test-load.phpto assert the new hook registrations.--group server-timing: 49 tests, 100 assertions — green on WP 7.0 (which includes the 6.9 API).performance-labtestsuite: green.phpcs+phpstanpass.Note: a true integration test asserting the emitted
Server-Timingheader is not feasible in the PHPUnit harness becausesend_header()'sheaders_sent()guard trips under CLI; coverage stays at hook-registration level, consistent with the existing tests.AI assistance
AI assistance: Yes
Tool(s): Claude Code (Anthropic)
Model(s): Claude Opus 4.8
Used for: Implementation, test updates, and code review (cross-checked with Grok); I have reviewed and take responsibility for the output.