Experience Builder will allow users to author components written in JavaScript using a built-in code editor. This feature mostly targets marketing teams with a sufficient level of design and frontend coding skills to author basic components, with no or minimal interactivity, primarily consisting of markup.
Terminology:
The user-facing name XB will use is code components. In technical language, we'll use JavaScript components.
Proof of concept:
#3483267: [exploratory] PoC of Preact+Tailwind components editable via CodeMirror
Issues

Legend

Must have for #3455753: Milestone 0.2.0: Early preview:
- #3499927: Config entity for storing code components
- #3499931: HTTP API for code component config entities
- #3498889: ComponentSource plugin for code components
- #3499933: Storage for CSS shared across in-browser code components (and other use cases in the future)
- #3499947: Managing code components in library
- #3499988: Editing code components
- #3500017: Defining props for code components
- #3500020: Ensure base path is available in client app for including static assets at runtime
- #3500034: Preview for code components
- #3500042: Auto-save code components
- #3500043: Publishing code components
- #3500058: Hydration library for code components
- #3500071: Adding code components to components
- #3500083: Managing components sourced as code components
- #3500081: Editing components sourced as code components
- #3502893: Create a badge element for navigating out of the code editor in the top bar
Nice to have for #3455753: Milestone 0.2.0: Early preview:
- #3508694: Permissions for XB config entity types
- #3499964: Component groups for primary components (theme-provided SDCs + code components)
Out of scope for #3455753: Milestone 0.2.0: Early preview:
- #3500074: Usage info for code components with unpublished changes
- #3500068: Console for developing code components Assigned to: hooroomoo
- #3499950: Authentication for CLI tools to manage code components Assigned to: lauriii
- #3499957: CLI tool to manage code components
Current Designs
Updated on 1.17.25. Here is a holistic view of the Code Editor for components and code overrides.
Add new code component

Panel behavior

Add code version to component library
This user flow showcases the two separate areas in the library for code components and those components that have been published for content editors to use. This allows for permissions to be set on each type of component (ie. Roberto the content editor would not have access to code components or overrides).

Edit and publish changes to an existing component
When editing an existing component in the library, a site developer like our persona Keith might want to make updates to the code. When he does so, he will need to publish those changes to all the instances that use that component. The review changes modal shows all the instances on the pages he will need to go review.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | Edit existing component.gif | 4.23 MB | bostonjillian |
| #5 | Add to library.gif | 453.24 KB | bostonjillian |
| #4 | Panel collapse.gif | 553.63 KB | bostonjillian |
| #4 | Add new code component updated nav.gif | 2.84 MB | bostonjillian |
| #3 | xb-code-components-dependencies-legend.png | 16.88 KB | balintbrews |
Comments
Comment #2
balintbrewsComment #3
balintbrewsComment #4
bostonjillian commentedComment #5
bostonjillian commentedComment #6
balintbrewsIn a Slack conversation about terminology between @effulgentia, @lauriii, @wim leers and myself, we decided the technical term we'll use for the new component source type is in-browser code components.
The "in-browser" prefix will be omitted in user-facing language and whenever the context is clear.
Comment #7
wim leers#6++ — I think all that is worth capturing in
docs/😊🤓 Perhaps indocs/components.md?Comment #8
balintbrews#7++ — I created #3500945: Documentation for code components. I suggest we wait with it until we tackle at least the issues I listed as blockers, so we have the full picture to write better docs. Until then, a brief explanation of the terminology is in the issue summary.
Comment #9
balintbrewsComment #10
wim leersA new challenge apepared: https://git.drupalcode.org/project/experience_builder/-/merge_requests/5... for #3498889: ComponentSource plugin for code components.
Remember that the way XB's UI is able to determine which parts of the (server-side rendered!) preview markup correspond to which components and slots is powered by HTML comments. Quoting
/ui/tests/unit/function-utils.cy.js, it looks like this:(Note the
xb-start-andxb-slot-start-.)And like this:
(Note the
xb-start-andxb-prop-start-.)While editing components and placing them in slots requires only the annotations from the first kind (component + slot), SDC-sourced XB components actually already have their props annotated too, which will enable us to provide (visual and otherwise) affordances connecting inputs in the
ComponentInputsFormform to very specific bits of markup in the preview. We're just not doing that yet. That work landed in preparation for #3453690: [META] Real-time preview: supporting back-end infrastructure.Because it's not yet actively used in XB, I explicitly +1'd not holding up #3498889 for that.
@larowlan pointed out in https://git.drupalcode.org/project/experience_builder/-/merge_requests/5... that we can keep generating
xb-start-andxb-slot-start-HTML comments, but thatxb-prop-start-is not actually possible. How did the folks working on the PoC envision supporting that?AFAICT the closest issue to that 👆 is #3500081: Editing components sourced as code components. But I figured I'd post on the meta/plan issue to avoid potentially derailing/blurring the scopes of #3500081. 😊
Comment #11
hooroomooAdding #3502893: Create a badge element for navigating out of the code editor in the top bar to the must have list, after discussing with @balintbrews
Comment #12
effulgentsia commentedNot in scope for 0.3, but if we want to support this at some point, I think we'd need to do it as part of the source_js -> compiled_js compilation. For example, perhaps prior to compiling with SWC, we first pass the source JS through Babylon to find where props are being output and inject the HTML comments into there.
Comment #13
larowlanMy understanding is that this was added to support a future state where we didn't need a round trip to the server to update the preview.
With code components, we don't do any server side rendering so I don't think we need to worry about props - we will already have client side updates right?
Comment #14
balintbrewsIn addition to that, wouldn't it be our way to support in-place editing further down the line?
In the initial implementation, prop values will be passed to the
<astro-island>tag in apropsattribute as JSON-encoded data. This markup is rendered in #3498889: ComponentSource plugin for code components, so it's server-side . That attribute would be quite simple to update client-side, but we haven't made any plans to do so yet.Comment #15
effulgentsia commentedYes to #13 but in addition there's also the desired future state where if, for example you click within the canvas on the part of the component where a prop is rendered, the ComponentInputsForm opens with focus on the corresponding widget.
Comment #16
larowlanThanks, both of those make sense. I forgot about in place editing 👍️
Comment #17
hooroomooadding a space just to update the issue summary issue statuses since we finished a sprint, is that how it's done?
Comment #18
wim leersIncredible progress the past 2 weeks! 🤩 Tested what landed last night, and found 2 problems, the first of which is definitely minor:
I think the first one is a NICE-TO-HAVE, the second one a
MUST-HAVESHOULD-HAVE (given time constraints).Comment #19
balintbrewsI just updated the terminology again (
s/in-browser/JavaScript) after @lauriii pointed out a while back that we can't call these components "in-browser", because we're planning to support creating them also via a CLI tool.Comment #20
wim leers#3500386: Code Components should render with their auto-saved state (if any) when rendered in the XB UI is missing from the issue summary. Is that intentional?
It also doesn't account for the fact that auto-saves are not guaranteed to be in a working state. Which means that once #3500386: Code Components should render with their auto-saved state (if any) when rendered in the XB UI is done, a temporarily broken code component could break all XB previews.
(For example: modifying the code to not output a slot, while the metadata does say that that slot exists.)
Comment #21
balintbrews#20: I didn't update the issue summary with the issues that expanded those in the main story map, especially with auto-save related work where we had many unknowns. I'm happy to add that issue if it deserves to be on the main story map.
Can you please give more examples of how things can be broken?
How would this break? Wouldn't it just not output the slot?
Comment #22
wim leersYes. And if 90% of the component tree happens to be in that slot, the result will be that suddenly all XB previews seem to be very broken because the majority of the content would be missing 😭😄
A different kind of breakage would be: the JS throws an error early on, causing it to not render anything at all. That might result in JS components having the same breakage as seen in the screenshot at #3485878: Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log), but there we know we can prevent that from ever happening for SDCs — we just haven't done it yet.
The breakage in #3485878: Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log) is due to invalid component inputs, which can happen for any component type. The concern I'm raising in #20 and here is that for auto-saved code components there is a completely new failure mode: invalid component logic. And #3500386: Code Components should render with their auto-saved state (if any) when rendered in the XB UI would cause that problem to instantly "spread" to all places where that code component is being used! 🧟
Comment #23
wim leersAdded #3508694: Permissions for XB config entity types.
Comment #24
wim leersShouldn't #3505993: Code Components as Block Overrides, step 1 be in here too?
Comment #25
wim leersReflecting that … ALL MUST-HAVES ARE DONE! 🤯🥳
Comment #26
wim leers@lauriii and I realized an hour ago that we need a code component sibling of #3453690: [META] Real-time preview: supporting back-end infrastructure.
Comment #27
wim leers@mayur-sose created #3514035: Creating multiple components with same label causes error: entity with ID already exists, which is a subset of #3503547: Display validation errors in dialogs that create sections.
Comment #28
wim leersWith #3518182: [Plan] First-party code component imports being the next important feature for in-browser code components … @balintbrews can we close this? 🤞
Comment #29
effulgentsia commentedRe #26, I opened #3514910: Refinements of real-time preview for props changes of JS components.
Re #28, this issue still has child issues for CLI tooling, but maybe we should open a new Meta/Plan issue for that and move those to there? Especially since this issue even has "in-browser" in its title :)
Comment #30
wim leers💯 This! 😄
Comment #41
balintbrewsYes, let's close this. 🙂🎉
All must-haves happened, I'll extract everything else into new meta issues.
Comment #43
balintbrewsComment #45
balintbrewsFTR, we now have #3525571: [Meta] CLI tool for code components.