-
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
Fix block selection issues in safari by avoiding conditional event handlers #30968
Conversation
Size Change: +1.43 kB (0%) Total Size: 1.47 MB
ℹ️ View Unchanged
|
Tested and works as expected. P.S. I was hoping that this would fix #30249 as well. But I can still reproduce the issue. Do you think it's also related to Async Mode? |
@youknowriad not yet. I will do tests later today. Thanks for reminding me. |
<BlockNavigation | ||
onSelect={ onClose } |
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.
This is actually a bug in trunk that is highlighted by this PR. (In a failing e2e test, focus was moving back to "inner block" after the parent was selected)
@@ -113,6 +113,9 @@ describe( 'List', () => { | |||
await clickBlockAppender(); | |||
await page.keyboard.press( 'Enter' ); | |||
await page.keyboard.type( '* ' ); | |||
// Not entirely certain why this timeout is needed. | |||
// eslint-disable-next-line no-restricted-syntax | |||
await page.waitFor( 1000 ); |
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.
@ellatrix any ideas here? I suspect the test to be unstable in trunk too, just less visible but I don't understand how this PR impacts this since it's pretty consistent here.
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'll look into it
getBlockRootClientId, | ||
getBlockIndex, | ||
} = select( blockEditorStore ); | ||
|
||
return { | ||
isSelected: isBlockSelected( clientId ), | ||
isBlockSelected: _isBlockSelected, | ||
rootClientId: getBlockRootClientId( clientId ), | ||
index: getBlockIndex( clientId ), |
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.
For all of these selectors, we could really use #31078. All of the results are only used in callbacks so it's pointless to call them here.
@@ -108,6 +108,10 @@ export function useEventHandlers( clientId ) { | |||
} | |||
|
|||
function onMouseLeave( { buttons } ) { | |||
if ( ! isBlockSelected( clientId ) ) { | |||
return; |
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'm not sure if it's a good idea to add this event handler to every block? It's only necessary for the selected block, there's no need to track mouse leaving for all the other blocks. Maybe there's barely a difference in performance though.
closing in favor of #31103 |
With Async Mode, useSelect calls for non selected blocks are not run synchronously which means the event handlers added conditionally by this hook are not attached on time after a block get deselected. This could potentially impact all browsers when the content of the post grows, it's just more visible in Safari.
Testing instructions