Problem

Atm when data is output as slot, the element name may be omitted instead of being simply drupal-markup:

screenshot

This has two problems:
a) it may be confusing since the element JSON is not recognizable as element JSON without an element name
b) rendering the element on the frontend atm does expect the the custom element name.

So atm the frontend needs to do take care of the default and complicate the code like this:

    <slot name="body">
      <component :is="useDrupalCe().renderCustomElements({
        element: $attrs.body.element ?? 'drupal-markup',
        content: $attrs.body.content,
      })" />
    </slot>

Proposed resolution

Let's add the drupal-markup default custom element name, so the frontend can rely on it and simplify the code as follows:

    <slot name="body">
      <component :is="useDrupalCe().renderCustomElements($attrs.body)" />
    </slot>

API changes

small change in behaviour, so maybe best do it only in v3.

CommentFileSizeAuthor
2024-09-10_22-53.png28.6 KBfago
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

Title: JSON serialization of slots should always sometimes omits the element name » JSON serialization of slots sometimes omits the element name

fago’s picture

Title: JSON serialization of slots sometimes omits the element name » SON serialization of markup only slots is broken
Status: Active » Needs review

While working on https://www.drupal.org/project/custom_elements/issues/3473677 I found out the real problem is not the missing element name, but the broken serialization of the markup format.

fago’s picture

roderik’s picture

Per yesterday evening (before the MRs), I had trouble reproducing the screenshotted situation and doubts whether the arrows even represented slots. I don't understand this serialization code enough.

Current issue status from my perspective:

I'm guessing it was introduced by #3455496: Drop simple and single+simple slot normaliziation styles .

While I can't reproduce the above, I will try to verify by reproducing #3473677: JSON serialzation of nested, single element broken (testing user login form).

This needs a test to make sure a bug like this does not sneak in again. After reproducing, I hope to be able to create a test and add it to https://git.drupalcode.org/project/custom_elements/-/merge_requests/93.

I'll also try to update our internal project to the latest custom_elements version, so I can run the associated tests, before committing this. (Per the README, this still needs us to create/check our own update path; I expect/hope that will be relatively quick.)

roderik’s picture

Title: SON serialization of markup only slots is broken » JSON serialization of markup only slots is broken
Related issues: +#3473677: JSON serialzation of nested, single element broken
roderik’s picture

reproduce the above (serialization of the markup format)

This seems way easier than I thought; it's basically the most simple version of a setSlot() call, and then serializing that.

I'm just not experienced enough to know, yet. (Anything that is called '*Slot*()' is still magic to me.)

I'll change course and commit this now, do a new beta release so people can work with probably-non-broken code, and think about a test later.

TODO ON ME: check if tests for JSON serialization can be easily added to this module or if e.g. lupus_ce_renderer is a better place.

  • roderik committed e32dfa2c on 3.x
    Issue #3473490 by fago: Fix JSON serialization of markup only slots
    
roderik’s picture

Status: Needs review » Fixed

@fago

* MR 93 had a branch in the origin repo. After pushing the above commit (including a phpcs fix), I deleted the branch which closed the MR.

* Opened a followup issue for creating the test later. (Juggling priorities before RC1.)

Status: Fixed » Closed (fixed)

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