Skip to content

Commit

Permalink
chore: skip first render
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev committed Jan 10, 2025
1 parent 13f8f79 commit 2624280
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 74,151 deletions.
8 changes: 6 additions & 2 deletions packages/base/src/UI5Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ abstract class UI5Element extends HTMLElement {
_internals: ElementInternals;
_individualSlot?: string;
_getRealDomRef?: () => HTMLElement;
_skipFirstRender?: boolean;

static template?: TemplateFunction;
static _metadata: UI5ElementMetadata;
Expand Down Expand Up @@ -234,7 +235,9 @@ abstract class UI5Element extends HTMLElement {
const ctor = this.constructor as typeof UI5Element;
if (ctor._needsShadowDOM()) {
const defaultOptions = { mode: "open" } as ShadowRootInit;
if (!this.shadowRoot) { // if there is already a declarative shadow root, do not destroy it
if (this.shadowRoot) { // if there is already a declarative shadow root, do not destroy it
this._skipFirstRender = true;
} else {
this.attachShadow({ ...defaultOptions, ...ctor.getMetadata().getShadowRootOptions() });
}

Expand Down Expand Up @@ -854,7 +857,8 @@ abstract class UI5Element extends HTMLElement {

// Update shadow root
if (ctor._needsShadowDOM()) {
updateShadowRoot(this);
updateShadowRoot(this, this._skipFirstRender);
this._skipFirstRender = false;
}
this._rendered = true;

Expand Down
8 changes: 5 additions & 3 deletions packages/base/src/updateShadowRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import getConstructableStyle from "./theming/getConstructableStyle.js";
import type UI5Element from "./UI5Element.js";

/**
* Updates the shadow root of a UI5Element or its static area item
* Updates the shadow root of a UI5Element (both CSS and HTML)
* @param element
*/
const updateShadowRoot = (element: UI5Element) => {
const updateShadowRoot = (element: UI5Element, skipDOMUpdate = false) => {
const ctor = element.constructor as typeof UI5Element;
const shadowRoot = element.shadowRoot;

Expand All @@ -15,7 +15,9 @@ const updateShadowRoot = (element: UI5Element) => {
}

shadowRoot.adoptedStyleSheets = getConstructableStyle(ctor);
ctor.renderer(element, shadowRoot);
if (!skipDOMUpdate) {
ctor.renderer(element, shadowRoot);
}
};

export default updateShadowRoot;
Loading

0 comments on commit 2624280

Please sign in to comment.