-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Allow direct selection of nested Page List block by avoiding dual rendering within block #45143
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Size Change: +138 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
Thanks for fixing this @getdave. I pushed a commit which extracts that logic to a function which means we can return early, which I prefer because it makes it much harder for bugs like this to happen again. What do you think? |
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 this looks great :) 👏🏻
Pretty sure the failing test is also failing on |
cc @ockham this will need backporting as it fixes a pretty big UX problem for the Navigation block in that the fallback placeholder (i.e. Page List) will not be selectable in canvas. |
Hey @getdave! Since these changes are JS-only, the "Backport to WP Beta/RC" label that you added is enough to bring it on our radar for our Monday triage session, and for inclusion in RC3 on Tuesday 😄 |
…dering within block (#45143) * Fix dual rendering within Page List * refactor the content of the block to a function Co-authored-by: Ben Dwyer <ben@scruffian.com>
I just cherry-picked this PR to the wp/6.1 branch to get it included in the next release: 7061258 |
Reverting on the |
|
…dering within block (#45143) * Fix dual rendering within Page List * refactor the content of the block to a function Co-authored-by: Ben Dwyer <ben@scruffian.com>
…dering within block (#45143) * Fix dual rendering within Page List * refactor the content of the block to a function Co-authored-by: Ben Dwyer <ben@scruffian.com>
What?
Fixes the Page List to make it selectable in the canvas when it is a child of a container block such as the Navigation block.
Closes #45083
Why?
In #45083 it was reported that it was impossible to directly select the Page List block when it was within a Navigation block. This was also reproducable when the Page List was nested inside other containers such as Group thus confirming that this was not a Nav block specific Issue.
How?
After a lot of deep diving (see Issue) I determine this was due to a
focusin
handler responsible for dispatching theselectBlock
action being _de-_registered on the Page List block node. This meant that despite being able to focus the block it was not being "selected" in the editor.The cleanup function that removes the
focusin
event listener is heregutenberg/packages/block-editor/src/components/block-list/use-block-props/use-focus-handler.js
Lines 62 to 64 in dc10788
This hook uses
useRefEffect
which is an effect which will run when theref
changes:gutenberg/packages/block-editor/src/components/block-list/use-block-props/use-focus-handler.js
Line 22 in 1b73e8b
The callback that removes the
focusin
with be called byuseRefEffect
when there is nonode
gutenberg/packages/compose/src/hooks/use-ref-effect/index.ts
Lines 38 to 40 in 1b73e8b
Therefore the registering of the
focusin
listener on the Page List node is due to the node being added/remove from the DOM.This made me immediately suspicious of the
render
method of Page List. After some debugging in the browser I was able to observe the Page List block node being rendered twice. I tracked this down to the following linesgutenberg/packages/block-library/src/page-list/edit.js
Lines 70 to 74 in 1b73e8b
gutenberg/packages/block-library/src/page-list/edit.js
Lines 91 to 98 in 1b73e8b
These are not mutually exclusive due to the later not being predicated on
hasResolvedPages
being truthy. Therefore it was possible for both the loading and the "resolved" rendering state of the block to be rendered at the same time. As both useblockProps
it was causing problems with the registeration of hanlders described above.The fix in this PR ensures that only one representation of the block can be rendered at any one time.
Testing Instructions
Before
http://localhost:8888/wp-admin/edit.php?post_type=wp_navigation
).After
http://localhost:8888/wp-admin/edit.php?post_type=wp_navigation
).<ul>
element.For bonus points also do the following (watch the screencast below to see how to do this):
focusin
listener.<ul>
node.onFocus
callback of theuseFocusHandler
hook.Screenshots or screencast
Screen.Capture.on.2022-10-20.at.09-30-48.mp4