Skip to content

Commit a571981

Browse files
refactor(Modals): avoid unnecessary use of createPortal (SAP#6242)
BREAKING CHANGE: modals are now rendered as children of the `Modals` component instead of being rendered into `document.body`
1 parent 868e3f5 commit a571981

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

docs/MigrationGuide.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ npx @ui5/webcomponents-react-cli@next codemod --transform v2 \
4646

4747
## General changes
4848

49-
## Minimal React Version
49+
### Minimal React Version
5050

5151
The minimum required `react` and `react-dom` version is now `18.0.0`.
5252

@@ -1066,6 +1066,9 @@ All Modal helper hooks have been removed. They can be replaced with the regular
10661066

10671067
The regular methods are now general purpose, so they can be used both inside the React content (components) as well as outside of the React context (redux, redux-saga, etc.).
10681068

1069+
In order to provide a place for the `Modals` helper to mount the popovers, you have to render the new `Modals` component in your application tree.
1070+
In addition, the modals are now rendered as children of the `<Modals>` component instead of `document.body` by default.
1071+
10691072
### ObjectPage
10701073

10711074
The newly introduced `DynamicPage` web component comes with its own `DynamicPageHeader` and `DynamicPageTitle` components, which are unfortunately incompatible with our `ObjectPage` implementation.

packages/main/src/components/Modals/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,15 @@ export function Modals() {
236236
<>
237237
{modals.map((modal) => {
238238
if (modal?.Component) {
239-
return createPortal(
240-
// @ts-expect-error: ref is supported by all supported modals
241-
<modal.Component {...modal.props} ref={modal.ref} key={modal.id} data-id={modal.id} />,
242-
modal.container ?? document.body
243-
);
239+
if (modal.container) {
240+
return createPortal(
241+
// @ts-expect-error: ref is supported by all supported modals
242+
<modal.Component {...modal.props} ref={modal.ref} key={modal.id} data-id={modal.id} />,
243+
modal.container
244+
);
245+
}
246+
// @ts-expect-error: ref is supported by all supported modals
247+
return <modal.Component {...modal.props} ref={modal.ref} key={modal.id} data-id={modal.id} />;
244248
}
245249
})}
246250
</>

0 commit comments

Comments
 (0)