Skip to content

Commit

Permalink
chore: filter out ui5 webcomponents in #whenFinished (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhan007 authored May 22, 2019
1 parent 1f62dda commit e6393ae
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/base/src/RenderScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,23 @@ class RenderScheduler {
return renderTaskPromise;
}

static getNotDefinedComponents() {
return Array.from(document.querySelectorAll(":not(:defined)")).filter(el => el.localName.startsWith("ui5-"));
}

/**
* return a promise that will be resolved once all ui5 webcomponents on the page have their shadow root ready
*/
static async whenShadowDOMReady() {
const undefinedElements = document.querySelectorAll(":not(:defined)");
const undefinedElements = this.getNotDefinedComponents();

const definedPromises = [...undefinedElements].map(
const definedPromises = undefinedElements.map(
el => customElements.whenDefined(el.localName)
);
const timeoutPromise = new Promise(resolve => setTimeout(resolve, 5000));

await Promise.race([Promise.all(definedPromises), timeoutPromise]);
const stillUndefined = document.querySelectorAll(":not(:defined)");
const stillUndefined = this.getNotDefinedComponents();
if (stillUndefined.length) {
// eslint-disable-next-line
console.warn("undefined elements after 5 seconds: ", [...stillUndefined].map(el => el.localName));
Expand Down

0 comments on commit e6393ae

Please sign in to comment.