Skip to content

Allow Query block variations to specify query attributes without defining innerBlocks #50457

@jeremyfelt

Description

@jeremyfelt

Description

I've registered a variation for a custom post type that sets an initial perPage value of 99 along with some other attributes.

When I first add the variation to the editor, I see:

<!-- wp:query {"query":{"postType":"person","perPage":99,"inherit":false},"namespace":"project/people"} -->
<div class="wp-block-query"></div>
<!-- /wp:query -->

I'm then presented an option to choose a pattern, which I expect. I select "Start blank" to choose one of the basic layouts provided for the query block. I then select "Title & Date" to populate a basic layout for the query.

This becomes:

<!-- wp:query {"queryId":1,"query":{"perPage":3,"pages":0,"offset":0,"postType":"person","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false},"namespace":"project/people"} -->

The originally selected variation's attributes have been overwritten by default attributes assigned to all core query variations.

My expectation is that the editor should respect the defaults I've applied to the initial variation.

Ideally, variations like "Title & Date" should only make changes to the layout of the Post Template block and not set any attributes in the query block. Less ideally, but also perfectly fine: it should merge itself with the first selected variation so that expectations can be set. Maybe an additional property of variations could be how they handle chaining?

In the current form, it seems that innerBlocks must be defined in the variation in order to have the variation attributes survive the initial insertion. The documentation kind of alludes to this, but it's not entirely clear.

Step-by-step reproduction instructions

  1. Register a block variation for core/query with perPage set to 99.
  2. Insert the block variation.
  3. Select "Title & Date".
  4. Expect perPage to be set to 99. See that it's set to 3.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.2 with and without Gutenberg 15.7.0 active.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions