Skip to content

refactor(Modals): avoid unnecessary use of createPortal #6242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/MigrationGuide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ npx @ui5/webcomponents-react-cli@next codemod --transform v2 \

## General changes

## Minimal React Version
### Minimal React Version

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

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

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.).

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.
In addition, the modals are now rendered as children of the `<Modals>` component instead of `document.body` by default.

### ObjectPage

The newly introduced `DynamicPage` web component comes with its own `DynamicPageHeader` and `DynamicPageTitle` components, which are unfortunately incompatible with our `ObjectPage` implementation.
Expand Down
14 changes: 9 additions & 5 deletions packages/main/src/components/Modals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,15 @@ export function Modals() {
<>
{modals.map((modal) => {
if (modal?.Component) {
return createPortal(
// @ts-expect-error: ref is supported by all supported modals
<modal.Component {...modal.props} ref={modal.ref} key={modal.id} data-id={modal.id} />,
modal.container ?? document.body
);
if (modal.container) {
return createPortal(
// @ts-expect-error: ref is supported by all supported modals
<modal.Component {...modal.props} ref={modal.ref} key={modal.id} data-id={modal.id} />,
modal.container
);
}
// @ts-expect-error: ref is supported by all supported modals
return <modal.Component {...modal.props} ref={modal.ref} key={modal.id} data-id={modal.id} />;
}
})}
</>
Expand Down
Loading