Skip to content

Focus lost after converting to another block #46844

@kevin940726

Description

@kevin940726

After converting a block to another block, the focus is lost, and keyboard shortcuts no longer work. We already have an e2e test for it:

I think I found the bug. I think this is an actual bug but could only happen when the interaction is slow enough. E2E test runs too fast so often it just won't error.

The issue is that after clicking "Convert to blocks", the button along with the block is destroyed, and the focus is lost. From that point on, pressing Cmd+Z does no effect and will only trigger the browser's default behavior (at least in Chrome). It can be easily reproduced when doing the test steps manually.

You can also reproduce it reliably locally after adding await page.waitForTimeout(3000); on Line 94 below:

// Convert to blocks and verify it worked correctly.
await clickBlockToolbarButton( 'Convert to blocks', 'content' );
await page.waitForSelector( '.wp-block[data-type="core/gallery"]' );
expect( await getEditedPostContent() ).toMatch( /<!-- wp:gallery/ );
// Check that you can undo back to a Classic block gallery in one step.
await pressKeyWithModifier( 'primary', 'z' );

The reason it sometimes passes is probably because the image is still loading/uploading, but I have no idea why 😅.

Originally posted by @kevin940726 in #36123 (comment)

Metadata

Metadata

Assignees

Labels

[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions