Template Part: Prevent infinite recursion#28456
Conversation
|
Size Change: +155 B (0%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
|
See #27012 where, for the server side rendering I implemented logic to detect recursion in nested blocks by adding and removing the block to a stack.
See #27612 for my original issue and test case data. The template part has a |
See reference below. Template parts are also a function of the theme, so that needs to be part of the identifier. |
|
Thanks for getting this PR started. It would be good to solve #28405 (comment), as you've pointed out, before generalising this server-side solution. Edit: fix opened at #28461. |
|
@bobbingwide, thank you for the helpful comment. It aligns with what @carlomanf commented in #28405 (comment) in relation to Reusable block:
We might as well merge the editor part for now and tackle the server-side separately based on the implementation you shared. |
d1f22bd to
4d3e092
Compare
|
@gziolo, can I help with this PR in any way? |
|
Feel free to take it over. I won't have time to work on it this week. |
Will do! |
4d3e092 to
e4a2a46
Compare
e4a2a46 to
26349a9
Compare
mcsf
left a comment
There was a problem hiding this comment.
Looking good! Let me know when you want a final review.
f4d36bd to
976d181
Compare
|
This is how it looks with template parts nested in themselves when browsing in the template parts view on the Edit Site page: nested-template-parts.movIt behaves a bit strange for the template part that is nested inside another template part, but it all makes sense. I would say it's an anti-pattern in the first place to nest the same template part inside itself so it doesn't explode but the result is random that should raise the flag for the theme author 😄 |
|
@aristath and @ntsekouras – this PR is ready for review and testing. It means we have Reusable Block and Template Parts covered. What else is missing? |
Post Content is missing. |
ntsekouras
left a comment
There was a problem hiding this comment.
Thanks for working on this @gziolo! I left a couple of comments but in my testing everything works as expected.
Great work on the addition to check ids with block 💯
packages/block-editor/src/components/use-no-recursive-renders/test/use-no-recursive-renders.js
Show resolved
Hide resolved
|
@mcsf and @ntsekouras - anything left to rework here? |
mcsf
left a comment
There was a problem hiding this comment.
Looks great. Thanks for circling back to this, and also for catching little things along the way.
|
Interesting, 5 unit tests fail on CI. I will investigate that and fix it before merging this PR.. |
It looks like there were some changes introduced in #29333. The hook uses now |
c0d5796 to
d68cfb8
Compare
Description
Fixes #27612.
Based on #28405 from @mcsf.
Tries to apply the same technique used for Reusable block to prevent infinite recursion when the same block is inserted into itself at any level of nesting.
Technical details
useNoRecursiveRendersrequired some improvements as there was the probability that the same unique id would be used for different block types. In theory, we could mitigate that by using the block name in the id but it would be up to the block author to ensure it. Instead, it uses the solution proposed by @mcsf to use the block edit context insideuseNoRecursiveRendersto resolve ambiguity on the framework level.How has this been tested?
WP_DEBUGandWP_DEBUG_DISPLAYconfig flags are enabled.a. Template Part A inside Template Part B that contains Template Part A.
b. Template Part A inside Template Part B that contains Template Part B.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue).
Checklist: