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.
Issue fork custom_elements-3630603
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
Comment #2
fagoComment #4
fagoAdded MR.
Comment #5
fagoThe 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:
setSlotFromNestedElements('rows', []))[]<template #rows>kept#markup/#plain_text(Canvas' default for an unpopulated slot), a#cache-only render array (empty or access-denied block), nested empty renderless containers<template>#prefix/#suffix/#theme_wrappers/#attachedOnly a bare
renderless-container(no attributes, no slot content, recursively) counts as "renders nothing". Thejson-renderformat is unchanged: it already drops named slots without children, so an emptyrowsis absent there as before.Comment #7
fagoSo merged!