Skip to content

Commit

Permalink
chore: Improves shadowed MFe mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-zahedi committed Mar 7, 2024
1 parent d668480 commit f37d681
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-lemons-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gdu': patch
---

gdu: Fixes mfe mounting
29 changes: 11 additions & 18 deletions packages/gdu/lib/mfe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,21 @@ interface Props {
projectName: string;
}

const queryShadowRoot = (
wrapElement: Array<Element>,
selector: string,
): Array<Element> | null => {
const queryShadowRoot = (wrapElement: Array<Element>, selector: string) => {
//Find element with no shadow root
if (wrapElement && wrapElement.length > 0) {
for (const element of wrapElement) {
if (element.childNodes.length === 0) {
return Array.from(element.querySelectorAll(selector));
// @ts-ignore
if (
element.firstChild.shadowRoot.firstChild.childNodes.length === 0
) {
// @ts-ignore
return element.firstChild.shadowRoot.querySelector(selector);
}
}
} else {
return null;
}
if (
wrapElement &&
// @ts-ignore
wrapElement.firstChild &&
// @ts-ignore
wrapElement.firstChild.shadowRoot
) {
// @ts-ignore
return wrapElement.firstChild.shadowRoot.querySelectorAll(selector);
}
return null;
};
export const getMfeMountPoint = ({
mountDOMId,
Expand All @@ -48,14 +40,15 @@ export const getMfeMountPoint = ({
mountDOMId || mountDOMClass,
'You must provide a mountDOMId or mountDOMClass',
);
debugger;
let point: HTMLElement | null = null;
const wrapElements = Array.from(
document.querySelectorAll(`.${mountDOMId || mountDOMClass}-wrap`),
);
if (typeof mountDOMId === 'string') {
point =
queryShadowRoot(wrapElements, '#' + mountDOMId) ||
document.querySelector('#' + mountDOMId)[0];
document.querySelector('#' + mountDOMId);
} else if (typeof mountDOMClass === 'string') {
const elements =
queryShadowRoot(wrapElements, '.' + mountDOMClass) ||
Expand Down

0 comments on commit f37d681

Please sign in to comment.