Skip to content

Commit cb1fc8b

Browse files
dbadurachriskari
andauthored
fix: Custom component rendering (#3842)
* wip * add ids to divs * add workaround for height problem * fix: don't redefine existing webcomponents * add another way to try to fix the height problem * fix import * remove workarounds --------- Co-authored-by: chriskari <chriskari@gmx.de>
1 parent abc00ee commit cb1fc8b

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

examples/busola-web-components/script.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,6 @@ class MyCustomPage extends HTMLElement {
111111
}
112112

113113
// Define the custom element
114-
customElements.define('my-custom-page', MyCustomPage);
114+
if (!customElements.get('my-custom-page')) {
115+
customElements.define('my-custom-page', MyCustomPage);
116+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div>
1+
<div id="extension-web-component">
22
<my-custom-page></my-custom-page>
33
</div>

src/components/Extensibility/ExtensibilityList.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { getExtensibilityPath } from 'components/Extensibility/helpers/getExtens
1212
import { useGetCRbyPath } from './useGetCRbyPath';
1313
import ExtensibilityCreate from './ExtensibilityCreate';
1414
import {
15-
useCreateResourceDescription,
16-
TranslationBundleContext,
17-
useGetTranslation,
1815
applyFormula,
19-
getTextSearchProperties,
2016
getResourceDescAndUrl,
17+
getTextSearchProperties,
18+
TranslationBundleContext,
19+
useCreateResourceDescription,
20+
useGetTranslation,
2121
} from './helpers';
2222
import { sortBy } from './helpers/sortBy';
2323
import { Widget } from './components/Widget';
@@ -198,6 +198,7 @@ const ExtensibilityList = ({ overrideResMetadata, ...props }) => {
198198
{isExtensibilityCustomComponentsEnabled && resMetaData.customHtml ? (
199199
<>
200200
<div
201+
id="custom-html"
201202
dangerouslySetInnerHTML={{ __html: resMetaData.customHtml }}
202203
></div>
203204
{createPortal(<YamlUploadDialog />, document.body)}

src/state/navigation/filters/areNodeFeaturesEnabled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const areNodeFeaturesEnabled = (
55
configFeatures: ConfigFeatureList,
66
): boolean => {
77
if (dependsOnConfigFeatures(node)) {
8-
if (isARequiredFeatureDisabled(node, configFeatures)) {
8+
if (isARequiredFeatureDisabled(node, configFeatures ?? {})) {
99
return false;
1010
}
1111
}

src/web-components/DynamicPageWebComponent.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { DynamicPageComponent } from 'shared/components/DynamicPageComponent/Dyn
44
import { ThemeProvider } from '@ui5/webcomponents-react';
55
import customCSS from 'shared/components/DynamicPageComponent/DynamicPageComponent.scss?inline';
66
import { parseHtmlToJsx } from './htmlTojsx';
7+
import { BrowserRouter } from 'react-router';
8+
import { Spinner } from 'shared/components/Spinner/Spinner';
9+
import { Suspense } from 'react';
710

811
function DynamicPageWithRecoil(props) {
912
const transformedForm = stickyHeaderHeight => {
@@ -15,10 +18,16 @@ function DynamicPageWithRecoil(props) {
1518
return (
1619
<RecoilRoot>
1720
<ThemeProvider>
18-
<DynamicPageComponent
19-
{...props}
20-
inlineEditForm={props?.inlineEditForm ? transformedForm : undefined}
21-
/>
21+
<BrowserRouter>
22+
<Suspense fallback={<Spinner />}>
23+
<DynamicPageComponent
24+
{...props}
25+
inlineEditForm={
26+
props?.inlineEditForm ? transformedForm : undefined
27+
}
28+
/>
29+
</Suspense>
30+
</BrowserRouter>
2231
</ThemeProvider>
2332
</RecoilRoot>
2433
);

src/web-components/createWebComponent.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function createWebComponent(
2424
connectedCallback() {
2525
if (!this.reactRoot) {
2626
this.reactRoot = document.createElement('div');
27+
this.reactRoot.setAttribute('id', 'component-root');
2728
this.appendChild(this.reactRoot);
2829
this.reactRootInstance = createRoot(this.reactRoot); // Initialize root
2930
}
@@ -138,7 +139,9 @@ function createWebComponent(
138139
}
139140
}
140141

141-
customElements.define(tagName, GenericWebComponent);
142+
if (!customElements.get(tagName)) {
143+
customElements.define(tagName, GenericWebComponent);
144+
}
142145
}
143146

144147
export default createWebComponent;

0 commit comments

Comments
 (0)