-
Notifications
You must be signed in to change notification settings - Fork 7
Web Components section #13
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
Changes from all commits
286a363
c67803d
639b0c4
62debf4
6acbdaa
4c60525
9933329
ddcb119
74c8aec
843007b
d3ec6ea
655e436
f2110b7
c25846a
bf03be7
ea43718
b68a22a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Web Components | ||
|
|
||
| The [WHATWG](https://html.spec.whatwg.org/multipage/custom-elements.html) and [WICG](https://github.com/WICG/webcomponents) maintain suite of web technologies and specifications including (but not limited to) | ||
|
|
||
| - [Custom Elements](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements) | ||
| - [Shadow DOM](https://dom.spec.whatwg.org/#shadow-trees) | ||
| - The [`<template>` element](https://html.spec.whatwg.org/multipage/scripting.html#the-template-element) | ||
| - The [`<slot>` element](https://html.spec.whatwg.org/multipage/scripting.html#the-slot-element) | ||
| - [`ElementInternals`](https://html.spec.whatwg.org/multipage/custom-elements.html#element-internals) | ||
| - [CSS Custom Properties](https://drafts.csswg.org/css-variables/) | ||
| - [Module scripts](https://html.spec.whatwg.org/#module-script) | ||
|
|
||
| These are collectively referred to as "web components", and represent the browsers' native component model for web developers. | ||
|
|
||
| Broadly speaking, every web component is a custom element - a specific tag-name which becomes associated with a class extending HTMLElement in JavaScript. Web components can also make use of the related technologies. | ||
|
|
||
| ## Recommended Components | ||
|
|
||
| - [Lit](https://lit.dev) (library and framework for authoring components) | ||
| - [Web Dev Server](https://modern-web.dev) / Web Test Runner (for unit tests and local dev) | ||
| - [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest) (for ide support / docgen / codegen) | ||
| - [PatternFly Elements](https://patternflyelements.org) Design System | ||
| - [Carbon Web Components](https://web-components.carbondesignsystem.com/) Design System | ||
| - [Web Components Community Group](https://github.com/w3c/webcomponents-cg/) | ||
|
|
||
| ## Guidance | ||
|
|
||
| ### Our Experiences Using Web Components at Red Hat | ||
|
|
||
| The team at Red Hat has been involved in several Web Component projects and have learned a good amount about Web Components and how to write them | ||
|
|
||
| Two Web Component "Systems" at Red Hat are | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like the real world examples and use cases here 👍 |
||
| - [PatternFly Elements](https://patternflyelements.org/) (aka PFE) (“upstream”) | ||
| - [Red Hat Design System](https://ux.redhat.com/) (aka RHDS) (“downstream”) | ||
|
|
||
| ### Advantages and Ideal Use Cases | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a section here on architecture:
With an emphasis on the concept that web components are agnostic to all those things, and thus can integrate with most or all. For example, there are implementations of redux, mobx, apollo, etc etc for web components |
||
|
|
||
| Through the teams experience with Web Components, we've identified a few different pros and cons when using Web Components and what type of applications you might want to use them with. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think it makes sense to add a bullet about web components being "Framework Agnostic"? A line about independence of web components in relation to react, vue or angular for example. Not sure if we want to show their usage alongside or independent of these frameworks as well. |
||
| #### Accessibility | ||
|
|
||
| a single implementation of complex ui patterns can help teams to ship accessible experiences with less fuss | ||
|
|
||
| #### Work Across frameworks / Cross Team Collaboration | ||
|
|
||
| the same `<rh-card>` which works in drupal can work the same way in react, or in an ejs template, and the teams working with those components can transfer that knowledge to other projects, instead of reimplementing design specs for each new framework. | ||
|
|
||
| #### Design Systems | ||
|
|
||
| The case for web component-based design systems is strong because of encapsulation / knowledge transfer / future proofing as described above. These can also include a certain amount of business logic like analytics code, personalization, etc (ymmv) | ||
|
|
||
| #### Microfrontends | ||
|
|
||
| This is another case where web components and shadow dom shine, as the encapsulation guarantees and framework interoperability aspects lend themselves naturally to enabling teams to cooperate while maintaining boundaries. | ||
|
|
||
| #### Greenfield SPA | ||
|
|
||
| There’s an argument to be made from a loading / rendering perf and future-proofing perspective to start new projects with a web component framework (like lit, stencil, hybrids, FAST, etc) in place of traditional / legacy framework (angular, react, vue) | ||
|
|
||
| docs.redhat.com (a greenfield project) leaned heavily on RHDS web components, and that helped ship the project faster | ||
|
|
||
| #### Piecemeal migration | ||
|
|
||
| The framework interoperability aspect enables upgrading complex projects on a component-by-component basis. Rather than break the entire app when bumping the underlying frontend-framework from vX to vY, replace components one by one with interoperable web components. | ||
|
|
||
| ### Common Gripes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we ought to flesh some of these out a bit |
||
|
|
||
| As with all programming models, there are some gotchas that the team has encountered: | ||
|
|
||
| - cross-root aria | ||
| - To prevent a11y failures, signifacant expertise might be needed | ||
|
|
||
| - double-registration errors when bundling modules. we recommend using a global import map for each page | ||
| - Server-side Rendering (SSR) gotchas. When using the `lit-ssr` library to generate [declarative shadow DOM templates](https://web.dev/articles/declarative-shadow-dom), hydration mismatches when client initial state differs from server rendered state can be difficult to recover from. | ||
| - shadow DOM can be a double edged sword. Teams which are unused to it may find it difficult to work with at first | ||
|
|
||
| - Unit Testing | ||
| - JSDOM/Jest may not work with your custom elements: teams may have to author their components with node environments / DOM shims in mind, which can increase payloads to the client in some cases. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we include or recommend testing strategies for web components then? Perhaps testing libraries like @open-wc/testing |
||
| - [@open-wc/testing](https://open-wc.org/docs/testing/testing-package/) is a testing framework that the team has had success with. | ||
|
|
||
| ### General Concensus | ||
|
|
||
| Authoring web components: If you have a team with web platform experience, that always have an MDN tab open, and you’re hopeful to leverage current and future web standards like PWA, then you’re likely to succeed. If on the other hand you don’t have much senior experience or depth of knowledge on web platform features, you may run into issues. However, your teams that overcome those issues will gain platform knowledge and not just framework knowledge. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if we'd like to emphasize on the performance considerations for web components.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. browser engines are able to optimize rendering based on the encapsulation guarantees, as well
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and lit's rendering performance beats react most of the time (scales with interpolations instead of nodes)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should link out to perf studies on lit and others, and emphasize that b/c wc relies on code already in the browser, it reduces page payloads for end users
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.youtube.com/watch?v=CJYkwDTaHzY vaadin lit vs react perf comparison
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://bennypowers.dev/decks/devconf-brno-2023/#slide-27/step-1 toy app page loading comparison (2023 devconf.cz) react: 2.5mb |
||
| Using web components inside of other major frameworks: our teams have consistently reported that consuming web components inside other frameworks is typically a turnkey developer experience which saves time and reduces duplication of effort. | ||
|
|
||
| Since Web Components rely on code that is already in the browser, they reduce the page load for the end user. | ||
|
|
||
| #### Resources | ||
|
|
||
| - [Vaadin lit vs Reac Performance Comparision](https://www.youtube.com/watch?v=CJYkwDTaHzY) | ||
| - [Page Loading Comparison - 2023 Devconf.cz](https://bennypowers.dev/decks/devconf-brno-2023/#slide-27/step-1) | ||
Uh oh!
There was an error while loading. Please reload this page.