Skip to content

fix(homepage-articles): reset dedup state per render pass (NPLAUNC-242) - #1019

Draft
leogermani wants to merge 3 commits into
releasefrom
fix/nplaunc-242-reset-dedup-per-render
Draft

fix(homepage-articles): reset dedup state per render pass (NPLAUNC-242)#1019
leogermani wants to merge 3 commits into
releasefrom
fix/nplaunc-242-reset-dedup-per-render

Conversation

@leogermani

@leogermani leogermani commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Saving or opening a page in the editor applies the_content to it more than once in the same request. WordPress renders content.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:

  • Deduplication restarts on every top-level the_content pass 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. The newspack_blocks_reset_deduplication_per_render_pass filter overrides the gate.
  • Article queries skip the SQL_CALC_FOUND_ROWS total 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 the no_found_rows change from NEWS-51.

Part of NPLAUNC-242.

How to test the changes in this Pull Request:

  1. Publish at least six posts. Create a page with three Content Loop blocks, each set to show one post, and publish it.
  2. Open the page on the front end. The three blocks show three different posts.
  3. Open the page in the editor and save it, with the browser's Network tab open. In the response to the POST /wp-json/wp/v2/pages/<id> request, content.rendered lists the same three posts as the front end.
  4. Repeat step 3 on release without this branch. content.rendered lists three different posts, none of them shown on the front end.
  5. With a block theme, add a Content Loop block to the front page template above the Post Content block. On the front end, the blocks inside the page do not repeat the template block's post.
  6. Add a Content Loop block with the More button enabled and fewer posts per page than exist. The More button shows and loads the next page.
  7. With Query Monitor active, view a page whose Content Loop blocks have no More button. Their wp_posts queries carry no SQL_CALC_FOUND_ROWS.
  8. From plugins/newspack-blocks, run n test-php --filter HomepagePostsBlockTest. All tests pass.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally? Full newspack-blocks suite passes in an isolated env.

Targets release as 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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_content pass depth tracking and reset deduplication state at the start of each top-level pass outside front-end requests (filterable).
  • Add a pre_render_block gate to skip query-backed blocks during wp_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.

@leogermani
leogermani force-pushed the fix/nplaunc-242-reset-dedup-per-render branch from 3115cfb to 8587a2b Compare September 2, 2026 15:42
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.

2 participants