-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Elements for Helix Blocks #211
Comments
Supported in all browsers relevant for Helix https://caniuse.com/mdn-api_window_customelements |
The easiest would be to use the version lock edge-dict and hardcode (custom--superdevoluy--kptadobe=ci112233) (@stefan-guggisberg we might not hardcode the pipeline version right now :-) |
Interesting! Fwiw, I started playing with using a shadow-DOMed web component for the sidekick to keep the page CSS from bleeding into it. Would love to share/compare outcomes. Since this issue is essentuially asking a question, should we turn it into a discussion? |
As of trieloff/superdevoluy@ce4c9f0 all blocks have been ported to custom elements. |
Minor concern: if the server gives me a |
After the complete porting, I've tried some more variants:
I've run the Chrome Profiler on each variant (using OriginalEager Custom ElementsLazy Custom ElementsNo Boiler PlateInline StylesSummary
|
Overview
Should we change the Markup generated by
helix-pipeline-service
for blocks (Tables in Word/GDocs) from genericdiv
to custom HTML elements?Details
I've built a tiny POC here https://github.com/trieloff/superdevoluy (thanks to @kptdobe for offering a small project to start with)
The site is using three types of block markup:
I'm loading the JS for the custom elements using
Where Helix as usual needs a small script to bootstrap the decoration of block
div
s like thisThe Custom Elements approach just uses the built-in features of the browser.
The code to register a block or custom element is very similar:
vs.
The
if
condition andthis.attachShadow({ mode: 'open' });
androot = this.shadowRoot;
are only needed if you want to use Shadow DOM, but without getting too much ahead of myself, you probably don't want to use Shadow DOM.The result are three blocks, styled slightly differently to outline the differences of the approaches:
Regular Custom Elements (green)
They behave just like normal elements, and the custom CSS rules in a separate file
work just as expected. There is no need to keep these rules in a separate file, you can just put them into the main CSS if you like – or not. Also note that a rule from the main CSS is able to seep into the compontent and add a
(strong)
into thestrong
tag's contents.Custom Elements with Shadow DOM (blue)
These elements behave as if they would be living in an
iframe
on the document, there is no external styling that can seep into the element, not even thebackground: green!important;
line from the custom CSS is able to override the inlinestyle="background: blue; margin-bottom: 50px;"
attribute.Note that neither the styling of the
strong
tag (with extra content) nor the styling of thea
tag is making it through, giving the entire component an extremely strong vanilla flavor.Unless you really, really hate the cascading nature of CSS, there is almost no reason to use Shadow DOM in Helix projects, as there is no boundary of trust between the person that writes the component and the person that writes the main CSS.
If you don't want Shadow DOM, the
Card
class can be simplified to:Helix as usual
Your block is just regular HTML on the page, with regular styling, albeit with the neccessity of a custom loader and a non-standard constructor API like this (repeated from above):
Proposed Actions
index.html
card.js
scripts for each of the custom elements (straight in the HTML, with a bootstrap script, etc.)div
s (@tripodsan any idea how we can turn this into a feature flag)The text was updated successfully, but these errors were encountered: