Problem

Canvas puts an empty string (`['#plain_text' => '']`) into every declared slot that the editor left empty. The fallback render converter wraps that in a `drupal-markup` element that has no content. Every output format then emits the slot anyway:

explicit:  "slots": {"actions": {"element": "drupal-markup"}}
legacy:    "actions": {"element": "drupal-markup", "content": []}
vue-3:     <template #actions><drupal-markup><div></div></drupal-markup></template>

So a frontend cannot tell an empty slot from a filled one. In Vue, `$slots.actions` is truthy, so the usual "slot, else prop fallback" pattern breaks:

Steps to reproduce

1. Place a Canvas component that declares two slots, and fill only one of them.
2. Fetch the page through the custom elements JSON API (explicit or legacy format), or render it as vue-3 markup.
3. The empty slot appears as `{"element": "drupal-markup"}` (or as `

` in markup).

Proposed resolution

The element stays in the tree with its cache metadata, and serialization outputs nothing for it.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fago created an issue. See original summary.

fago’s picture

Issue summary: View changes

fago’s picture

Status: Active » Needs review

Added MR.

fago’s picture

The MR code is good and gives the right results. Ran it against our internal distribution and checked API-response diffs also, seems all good. All it drupals slots with empty "drupal-markup" custom elements.

So here is a summary of the logic that it implements (ai generated):

When a slot is dropped from the output and when it is kept:

Slot content Explicit / legacy JSON vue-3 markup
Set without entries, e.g. a view with no results (setSlotFromNestedElements('rows', [])) kept as [] &lt;template #rows&gt; kept
Only entries that render nothing: an empty-string #markup / #plain_text (Canvas' default for an unpopulated slot), a #cache-only render array (empty or access-denied block), nested empty renderless containers slot omitted, cache metadata bubbles to the parent no &lt;template&gt;
Mix of such entries and real content kept, empty entries filtered out, list re-indexed kept, only the real entries rendered
Real content, including a named custom element without children or markup with #prefix / #suffix / #theme_wrappers / #attached unchanged unchanged

Only a bare renderless-container (no attributes, no slot content, recursively) counts as "renders nothing". The json-render format is unchanged: it already drops named slots without children, so an empty rows is absent there as before.

  • fago committed 173d0388 on 3.x
    fix: #3630603 Empty slots serialize as empty drupal-markup wrappers...
fago’s picture

Status: Needs review » Fixed

So merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.