[PP-1] Editing code components as overrides, step 1

Created on 12 February 2025, about 2 months ago

Overview

From the issue summary of โœจ Code Components as Block Overrides, step 1 Active (blocks this issue):

The first sentence on https://www.drupal.org/project/experience_builder โ†’ starts with:

The Drupal Experience Builder module will 1) enable site builders without Drupal experience to easily theme and build their entire website using only their browser

"entire website" includes blocks, such as menu blocks, breadcrumb block, etc. So what we want is for an in-browser-editable JS code component to be able to take over the entire HTML rendering of a block. That way, a site builder can customize the HTML and CSS for blocks the same way as they can for "regular" code components.

Proposed resolution

Start with a minimal implementation that doesn't allow creating overrides from the UI, but presents existing ones similar to code components, with reduced functionality. This will allow us to provide an initial set of overrides as config entities (e.g. shipped in a submodule).

User interface changes

  1. Display a list of code components relying on the override property introduced in โœจ Code Components as Block Overrides, step 1 Active as a new list in the primary sidebar titled "Overrides". Reuse the solution introduced in โœจ Managing code components in library Active .
  2. Do not allow deleting these code components.
  3. Do not allow adding these code component as components: this may only be relevant in โœจ Adding code components to components Active , whichever issue lands sooner.
  4. Present example input in place of Component data. Use the static JSON files containing sample prop and slot values added in โœจ Code Components as Block Overrides, step 1 Active and follow-up issues.
โœจ Feature request
Status

Postponed

Version

0.0

Component

Page builder

Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands balintbrews Amsterdam, NL

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @balintbrews
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    โœจ Code Components as Block Overrides, step 1 Active is on track to being finished. I think the front-end work can begin on top of the current MR! ๐Ÿ˜Š

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands balintbrews Amsterdam, NL

  • First commit to issue fork.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Manual testing: getting started

    When doing manual testing, I couldn't figure out how to create these from the UI. I was worried that I was doing something wrong. Then I was worried that xb_dev_js_blocks should not have been hidden in the UI (using package: Testing).

    But then I discovered the reassuring statement by @balintbrews in the issue summary:

    Start with a minimal implementation that doesn't allow creating overrides from the UI, but presents existing ones similar to code components, with reduced functionality. This will allow us to provide an initial set of overrides as config entities (e.g. shipped in a submodule).

    All good!

    Is it intentional that xb_dev_js_blocks's config is not enforced?

    Note: uninstalling and reinstalling xb_dev_js_blocks does not cause the block-overriding code components to be recreated. That means that sites won't get updated config. This seems fine, but I wanted to double-check.

    Manual testing: the menu block override has a JS error

    I was able to edit the "Breadcrumb" and "Site branding" block overrides in the code component editor, and the preview updated live โ€” awesome!

    But for the "Navigation menu" one, the preview didn't render. It showed:

    index.js:148 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__H')
        at l (index.js:148:19)
        at I (index.js:181:20)
        at B (index.js:168:9)
        at A.NavigationMenu [as constructor] (43d49346-52be-4dcb-aece-2d02a3de425c:5:29)
        at A.ve [as render] (index.js:665:14)
        at z (index.js:241:14)
        at oe (children.js:97:16)
        at z (index.js:267:13)
        at ye (render.js:42:2)
        at code-editor-preview.js:73:3
    

    in the console.

    But in @balintbrews's GIF in #5, it did work. ๐Ÿค”

    So I tried to see if there's anything off about this in either JavaScriptComponent::getExperimentalHardcodedBlockProps(), template_preprocess_menu__as_js_component(), or the test values at experimental/js-components-as-block-overrides/example-data/system_menu_block.json.

    There's only one problem I found: the label slot. The test values specify it as:

      "slots": {
        "label": "<div>Main navigation</div>"
      }
    

    Whereas the code renders it as:

            aria-label={label}
    

    ๐Ÿ‘† markup clearly does not belong in there โ€” an ARIA label should be assigned plain text, not markup.

    So which is right, which is wrong? ๐Ÿค” Looking at template_preprocess_menu__as_js_component(), I find:

      $slots = [
        'label' => $block_variables['label'] ?: $block_variables['configuration']['label'],
      ];
    

    That's clearly a plain-text label.

    Which leads me to conclude that the very definition for system_menu_block is wrong โ€” it doesn't have any slots.

    Conclusion

    I don't know what the original thinking is that led to "label" being a slot for menu blocks, so I defer to @effulgentsia and @balintbrews to address this in a follow-up. Meanwhile this MR brings this functionality alive, so merging with this known bug ๐Ÿ‘

    It was pretty cool to see my in-browser modified branding block appear on the live site ๐Ÿ˜„๐Ÿคฉ

  • Pipeline finished with Skipped
    about 1 month ago
    #435674
  • Pipeline finished with Skipped
    about 1 month ago
    #435683
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Assigning to Bรกlint for #menu-block-override-js-error in #7, which I bet (and hope) will be trivial for him ๐Ÿ˜„๐Ÿคž

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands balintbrews Amsterdam, NL

    #7:

    That's clearly a plain-text label.

    Okay, so let's make it so! MR is incoming. Why this broke in your browser, and not in mine is a mystery, but I'm glad you caught this.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands balintbrews Amsterdam, NL
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Huh! So I guess I did find the root cause! I actually tried doing exactly what you did here, but couldn't get it to work. Must've been a caching/wrong state problem.

    Manually tested (on a fresh install), and it works:

    ๐Ÿคฉ

  • Pipeline finished with Skipped
    about 1 month ago
    #435840
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nagwani
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024