-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post Template Block: Move inner blocks container to separate component #35945
Post Template Block: Move inner blocks container to separate component #35945
Conversation
Size Change: +31 B (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to reproduce the issue and the PR solves it for me.
I didn't get too deep into debugging, but I'm also not totally sure why this change was needed. I did verify that I can see the issue on trunk, and that it is resolved on this branch for me as well 👍 |
@@ -149,7 +154,7 @@ export default function PostTemplateEdit( { | |||
> | |||
{ blockContext === | |||
( activeBlockContext || blockContexts[ 0 ] ) ? ( | |||
<li { ...innerBlocksProps } /> | |||
<PostTemplateInnerBlocks /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes a lot of sense because in practice this creates a list of Post Template inner blocks so all block props should be computed in that context that is set by the BlockContextProvider
.
@michalczaplinski, we will need to apply the same changes as in the final version of this PR to the Comment Template block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #36174 to align the Comment Template block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoop, sorry for getting to this late @gziolo and thanks for taking care of this! 😊
3af2d19
to
5678a1d
Compare
Thanks for confirming, @gziolo! I've given this a rebase to keep it current and re-tested and it still appears to be working well, so I'll merge this in now. Happy to do any follow-ups if there are any issues. |
Description
This PR moves the inner blocks container for the Post Template block to a separate component, to ensure that the result of
useInnerBlocksProps
is always applied to same React node relative to the call to the hook.I'm not 100% sure why this fixes it, but it resolves the following issue:
Before: in a long Post Template block within a long query loop (e.g. within the Index template of the TT1-Blocks theme with 2+ published posts) if you click on a block within the first post within the loop, then scroll down to click on a similar block within another post within the loop, then the scroll position of the editor moves when the parent Post Template block is selected.
After: on click, the selection changes, but the scroll position does not move away unexpectedly.
How has this been tested?
Note: there is a separate issue that on the first click, the Post Template block is selected instead of the target block. That's logged in issue #35944 and is to do with the way the Post Template block only renders one post at a time as live editable blocks (the other posts are rendered as BlockPreviews). This PR only seeks to address the scrolling issue
Screenshots
Note: in the before screenshot, after clicking the similar block in the next post, the viewport is scrolled to the bottom of the page unexpectedly. In the After screenshot, the viewport is not scrolled unexpectedly (but it still takes a couple of clicks to activate the desired block as noted in #35944)
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).