WordPress/gutenberg

Automatically set `reusable` to `false` when a block has a `parent` defined

fabiankaegy opened this issue ยท 7 comments

What problem does this address?

When a block defines a parent that means that it gets hidden from the inserter unless you are trying to insert it into the defined parent. The block also cannot be moved outside of the container. However, it is still possible to select the "child" block and make it reusable. You can circumvent this by setting reusable to false but I think that should be the default behavior when a block has a parent defined.

What is your proposed solution?

The possible solution for this would be to automatically set the reusable flag to false by default for when a block has a parent defined.

So you are proposing that all block types that have a parent or multiple parents explicitly defined should never be set as reusable blocks. I tend to agree with that. @WordPress/gutenberg-core, what do you think?

mtias commented

I'm inclined to agree.

@gziolo I would love it to not be as strict. I think that it would be a great default and I cannot currently see any examples where you would want it. But that doesn't mean there isn't one.

So if we can make it work in a way where the developer could still set reusable to true explicitly to override the default value I think that would be the most flexible solution.

Seems like a good idea... but being able to override the default would be great and there would be no downsides to doing it.
There are some cases where I can imagine it would make perfect sense to have a child as a reusable block

being able to override the default would be great and there would be no downsides to doing it.
There are some cases where I can imagine it would make perfect sense to have a child as a reusable block

I bet we don't check the context when inserting a reusable block so that's a related area that needs further improvements. To ensure that the reusable block can be inserted only in the place where the outer block would be. To give an example, if the Button block has parent set as the Buttons block and you make Button reusable, then you should be able to insert it only inside the Buttons block.

@fabiankaegy @gziolo checking with the both of you to see if this is something worth pursuing still?

gziolo commented

Yes, it is still a valid issue, and it looks like we agreed on the way to address it. It shouldn't be that much work to implement it so maybe it could even be a candidate for a Good First Issue.