Skip to content

Using dispatch( 'core/editor' ).selectBlock for a nested block focuses on its inner child instead #9212

@miina

Description

@miina

Describe the bug
We are creating UI for being able to select nested blocks from a list of links. Added a new component which displays a root-level block and its inner first level children in a list of links. Clicking on a link triggers dispatch( 'core/editor' ).selectBlock( clientId ) with the relevant block's clientId. For some reason instead of the block with the specified clientId being selected its first inner child gets selected.

For example if the blocks are nested A > B > C then calling dispatch( 'core/editor' ).selectBlock( clientId ) with the clientId of B focuses on the block C is instead. Debugging clientId on these lines shows that for some reason this runs twice -- first time with the correct clientId and the second time with the clientId of the first inner block (C).

Note that using selectBlock with the root level element (A in the example) selects the correct block.

PR and the line in the PR using selectBlock: https://github.com/Automattic/amp-wp/pull/1347/files#diff-34cc40d7d5ae6b1abcceb3757490f8ecR45

Expected behavior
The block which clientId is used with dispatch( 'core/editor' ).selectBlock should be selected.

Additional context

  • Gutenberg version: 3.6.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Nested / Inner BlocksAnything related to the experience of nested/inner blocks inside a larger container, like Group or P[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions