@cather/kwc-synthetic-shadow
v1.0.0
Published
Synthetic Shadow Root for KWC
Downloads
9
Readme
Synthetic Shadow Root
Summary
This is a polyfill for ShadowRoot that was tailor-made for KWC in order to meet the performance goals of the Lightning Platform. This doesn't mean that it cannot be used with any other framework, but we took shortcuts and made compromises that might not align well with other frameworks.
Compromises
- Default content for
<slot>elements is always empty. slotchangeis only available directly on the<slot>(it doesn't bubble as in the case of the native implementation). This restriction is in place because implementingslotchangerequires usingMutationObserverwhich is expensive at runtime. By only supportingslotchangeevent applied directly on the<slot>element, the KWC engine receives a clear signal that the component author is interested in listening to this event. This avoids spending unnecessary CPU time when theslotchangeevent is never consumed.- If you use
MutationObserverto watch changes in a DOM tree, disconnect it or you will cause a memory leak. Note that a component can observe mutations only in its own template. It can't observe mutations within the shadow tree of other custom elements.
