fix(homepage-articles): reset dedup state per render pass (NPLAUNC-242) - #1019
fix(homepage-articles): reset dedup state per render pass (NPLAUNC-242)#1019leogermani wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L7GEKCoC1f2rvH5SHFeHA4
There was a problem hiding this comment.
🔵 Needs a closer look
It changes global rendering behavior by hooking the_content at extreme priorities and conditionally short-circuiting block rendering during saves, which can have broad site-wide impact beyond the covered test cases.
Pull request overview
This PR addresses request-scoped post deduplication leaking across repeated the_content render passes (notably in editor/REST saves), ensuring Content Loop (homepage-articles) and Carousel blocks produce consistent results per top-level render pass while preserving front-end request-wide dedup behavior. It also introduces an optimization to skip rendering query-backed blocks during post save hooks (targeting Yoast-style link counting) to avoid wasteful queries for output that is not user-visible.
Changes:
- Add
the_contentpass depth tracking and reset deduplication state at the start of each top-level pass outside front-end requests (filterable). - Add a
pre_render_blockgate to skip query-backed blocks duringwp_insert_post/save_post(filterable). - Add PHPUnit coverage validating front-end vs admin/REST behavior, nested-pass behavior, and both new filters.
File summaries
| File | Description |
|---|---|
| plugins/newspack-blocks/includes/class-newspack-blocks.php | Adds the_content pass lifecycle hooks to reset dedup state per top-level pass (non-front-end) and a save-time pre_render_block skip for query-backed blocks. |
| plugins/newspack-blocks/tests/test-homepage-posts-block.php | Adds tests for per-pass dedup reset logic (including nested-pass protection) and for skipping query-backed blocks during save, with filter overrides. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L7GEKCoC1f2rvH5SHFeHA4
3115cfb to
8587a2b
Compare
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L7GEKCoC1f2rvH5SHFeHA4
All Submissions:
Changes proposed in this Pull Request:
Saving or opening a page in the editor applies
the_contentto it more than once in the same request. WordPress renderscontent.rendered, renders it again after applying Block Hooks, and Yoast SEO renders it a third time on save to count links. Content Loop and Carousel blocks remember which posts they showed in a request-wide global that was never cleared, so each pass excluded everything the earlier passes showed. On a homepage with 28 blocks, one save fetched 185 posts to display 62, and the content handed back to the editor could not match the live page.Two changes, in separate commits:
the_contentpass outside front-end requests (admin, REST, cron, CLI). Each pass now returns the same posts, and the repeated queries are served by WP_Query's result cache. Nested passes, such as a Query Loop rendering Post Content, keep the state of the pass they belong to. Front-end rendering is unchanged, so a block theme with Content Loop blocks in the template above the post content keeps excluding those posts. Thenewspack_blocks_reset_deduplication_per_render_passfilter overrides the gate.SQL_CALC_FOUND_ROWStotal unless the block shows a More button. The total is only read to decide whether a next page exists. Profiled on the affected site, the count was 91 percent of each query's time. This is theno_found_rowschange from NEWS-51.Part of NPLAUNC-242.
How to test the changes in this Pull Request:
POST /wp-json/wp/v2/pages/<id>request,content.renderedlists the same three posts as the front end.releasewithout this branch.content.renderedlists three different posts, none of them shown on the front end.wp_postsqueries carry noSQL_CALC_FOUND_ROWS.plugins/newspack-blocks, runn test-php --filter HomepagePostsBlockTest. All tests pass.Other information:
Targets
releaseas a hotfix. Yoast's save-time render still runs; it is handled by turning off the text link counter in Yoast's site settings rather than in code. Not yet verified against the El Sol clone.🤖 Generated with Claude Code
https://claude.ai/code/session_01L7GEKCoC1f2rvH5SHFeHA4