fix: track seen blocks to prevent infinite recursion in cache checks#2327
Merged
jason10lee merged 4 commits intotrunkfrom Apr 1, 2026
Merged
fix: track seen blocks to prevent infinite recursion in cache checks#2327jason10lee merged 4 commits intotrunkfrom
jason10lee merged 4 commits intotrunkfrom
Conversation
adekbadek
approved these changes
Apr 1, 2026
Member
There was a problem hiding this comment.
Looks good! Verified the fix locally:
- Trunk: self-referencing synced pattern → HTTP 500 (OOM crash) ✗
- This branch: same pattern → HTTP 200, page renders normally ✓
- Non-recursive patterns render correctly ✓
- Mutual recursion (A ↔ B) handled gracefully ✓
Two minor nits inline.
|
Hey @jason10lee, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
matticbot
pushed a commit
that referenced
this pull request
Apr 2, 2026
## [4.26.1-alpha.1](v4.26.0...v4.26.1-alpha.1) (2026-04-02) ### Bug Fixes * **modal-checkout:** register NYP AJAX handler for logged-out users ([#2323](#2323)) ([291223e](291223e)) * reinstate WP 7.0 enqueue_block_assets workaround ([#2319](#2319)) ([4cff5a6](4cff5a6)) * track seen blocks to prevent infinite recursion in cache checks ([#2327](#2327)) ([9116fc0](9116fc0))
|
🎉 This PR is included in version 4.26.1-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
matticbot
pushed a commit
that referenced
this pull request
Apr 13, 2026
## [4.26.1](v4.26.0...v4.26.1) (2026-04-13) ### Bug Fixes * **modal-checkout:** register NYP AJAX handler for logged-out users ([#2323](#2323)) ([291223e](291223e)) * reinstate WP 7.0 enqueue_block_assets workaround ([#2319](#2319)) ([4cff5a6](4cff5a6)) * track seen blocks to prevent infinite recursion in cache checks ([#2327](#2327)) ([9116fc0](9116fc0))
|
🎉 This PR is included in version 4.26.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
A synced pattern containing a
core/blockreference to itself (or a cycle of patterns referencing each other) causes infinite recursion inNewspack_Blocks_Caching::check_block_cache_status(). The method recurses into reusable block content viaget_post()+parse_blocks(), but never checks whether it has already visited a given block ID. This leads to an OOM crash on the front end for logged-out visitors, since logged-in admins bypass the cache path entirely.This was observed on a live site where a synced pattern accidentally contained a self-referencing
<!-- wp:block {"ref":14406} /-->, causing 500 errors on any page that embedded it.This PR adds a static
$visited_reusable_blockstracker that mirrors the approach used by WordPress core'srender_block_core_block()(source). When a reusable block ID is encountered a second time during the same traversal, it is skipped. The visited set is scoped per top-level call: entries are added before recursing and removed after, so the same block can still appear in unrelated branches of the block tree.Also adds a guard for empty
refattributes to avoid passing a falsy value toget_post()(because of course it'll happen!).Addresses NPPM-2706 Guard against infinite recursion in included blocks.
How to test the changes in this Pull Request:
Setup:
ncd newspack-blocks # or: cd repos/newspack-blocks n ci-build1. Verify existing tests pass:
Manual testing (browser)
2a. Create a recursive synced pattern:
post=<ID>).3a. Verify the fix:
4a. Confirm non-recursive patterns still render:
Alternative: CLI testing using
newspack-workspace2b. Create a self-referencing synced pattern and verify the fix prevents a crash:
3b. Confirm non-recursive synced patterns still render normally:
4. Cleanup (optional):
Other information: