fix(collections): preserve inner blocks in card indicator#407
Conversation
Co-Authored-By: Laurel Fulford <laurel.fulford@automattic.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KyqFFJm1pq4RgHDgyAKWe
dkoo
left a comment
There was a problem hiding this comment.
Confirmed the fix and the blocker (details inline) in manual testing.
Thanks for porting this — the core fix is right and the regression test is a good guard. render_block() is the correct way to reassemble parsed blocks so inner blocks (list items, columns) and dynamic blocks survive, and I confirmed the existing suite (14 tests / 56 assertions) passes on this branch.
One blocker before merge: rendering blocks inside the the_content priority-1 filter introduces a re-entrancy regression. self::$the_content_has_rendered is set only after insert_after_nth_block() runs, so a dynamic block that re-applies the_content during that render (Query Loop / core/post-content, core/template-part, core/post-time-to-read) re-enters the indicator filter with the guard still false. The result: a card-style post that is in a published collection and contains such a block injects the outer post's collection card into the nested/queried post's content — and that output is cached for all readers. I reproduced this in a live env (WP 7.0). It's a one-line fix plus a regression test. There's also a smaller test-brittleness suggestion below.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KyqFFJm1pq4RgHDgyAKWe
|
Thanks for the thorough manual review @dkoo - all three points addressed in da9f45b:
Full suite green (15 tests, 63 assertions). |
dkoo
left a comment
There was a problem hiding this comment.
Thanks for the updates, @adekbadek! All three points from the previous review are addressed and verified. The guard is now set before the blocks are rendered, so a dynamic block that re-applies the_content during the card render (Query Loop / core/post-content, etc.) short-circuits on re-entry instead of leaking the outer post's collection card into nested/queried content; there's a dedicated regression test asserting the card renders exactly once. The test assertions no longer couple to the WP 7.0+ wp-block-paragraph class, and the inner-blocks test now locks in list-wrapper placement and ordering.
I re-verified on the live front-end: the Query Loop collection post that previously rendered three cards (two leaked into the queried siblings) now renders exactly one, with the list-block post still rendering its items correctly. Full suite green (15 tests / 63 assertions). LGTM — thanks for the quick, thorough turnaround.
|
Hey @adekbadek, 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! ❤️ |
## newspack [6.44.1](https://github.com/Automattic/newspack-workspace/compare/newspack@6.44.0...newspack@6.44.1) (2026-06-30) ### Bug Fixes * **collections:** preserve inner blocks in card indicator ([#407](#407)) ([96f5e6e](96f5e6e))
## [4.26.7](https://github.com/Automattic/newspack-workspace/compare/newspack-blocks@4.26.6...newspack-blocks@4.26.7) (2026-06-30) ### Bug Fixes * **checkout:** sync repeat trial pricing in modal checkout ([#264](#264)) ([#468](#468)) ([d7d2356](d7d2356)) * **collections:** preserve inner blocks in card indicator ([#407](#407)) ([96f5e6e](96f5e6e))
## [2.23.7](https://github.com/Automattic/newspack-workspace/compare/newspack-theme@2.23.6...newspack-theme@2.23.7) (2026-07-09) ### Bug Fixes * **access-control:** restore long-lived institutional IP access cookie ([14b3aad](14b3aad)), closes [#136](#136) [#4749](https://github.com/Automattic/newspack-workspace/issues/4749) [#4749](https://github.com/Automattic/newspack-workspace/issues/4749) * **blocks:** restrict articles endpoint to viewable post types ([cde3e84](cde3e84)) * **checkout:** sync repeat trial pricing in modal checkout ([#264](#264)) ([#468](#468)) ([d7d2356](d7d2356)) * **collections:** preserve inner blocks in card indicator ([#407](#407)) ([96f5e6e](96f5e6e)) * **content-gate:** keep commenting per Discussion Settings on metered posts (NPPD-1829, [#459](#459)) ([43d4fc6](43d4fc6)) * **group-subscription:** render metabox on non-HPOS order storage ([#426](#426)) ([c542f0b](c542f0b)) * **group-subscription:** validate invite before creating an account ([ee44068](ee44068)) * **listings:** authorize self-serve premium listing create/delete ([#507](#507)) ([60efb47](60efb47)) * **newsletters:** add status control to ads quick edit ([#478](#478)) ([4a3fab1](4a3fab1)) * **newsletters:** limit ad editor status to active/inactive ([d7c741c](d7c741c)) * **oauth:** verify Google token audience on sign-in ([9aa30b9](9aa30b9)) * **popups:** restrict prompt preview to prompt managers ([c763c38](c763c38)) * **reader-activation:** load RAS scripts after commons (NPPM-2951) ([#414](#414)) ([d2dab16](d2dab16)) * **salesforce:** verify WooCommerce webhook signature ([80ab615](80ab615)) * **themes:** remove unintended highlight behind colored text ([#574](#574)) ([d94254c](d94254c)) ### Features * **gates:** capture gate id on landing-page conversions (NPPD-1887) ([#575](#575)) ([20e84f8](20e84f8)) * **newsletters:** dated per-ad impression/click stats (NPPD-1861) ([#543](#543)) ([078271d](078271d))
All Submissions:
Changes proposed in this Pull Request:
Monorepo port of Automattic/newspack-plugin#4726 (by @laurelfulford). The original PR fixed this in the legacy
newspack-pluginrepo, but the same bug still exists unfixed in the monorepo, which is now the primary release source. Code is from the original PR; this PR carries it to where it ships.In Collections, the 'Card' Collection Indicator Style reassembled post content from
$block['innerHTML'], which drops inner blocks - e.g.core/list-itemchildren of acore/list, or columns in a Columns block. Switching torender_block( $block )preserves inner blocks (and renders dynamic blocks correctly).Also includes:
test_insert_after_nth_block_preserves_inner_blocks) asserting<li>items survive.wp-block-paragraphclass now emitted byrender_block().Closes NPPM-2831.
How to test the changes in this Pull Request:
<ul></ul>(items dropped). After it, the items appear.Unit-level:
n test-php --filter Content_Inserter(14 tests, 56 assertions). The regression test fails on the oldinnerHTMLcode (empty<ul>) and passes withrender_block().Other information: