Skip to content

Commit

Permalink
[core] break(Portal): stop using legacy context in React 18 (#6680)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Jan 30, 2024
1 parent def9459 commit a1fc694
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/common/utils/reactUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ export function isElementOfType<P = {}>(
element.type.displayName === ComponentType.displayName
);
}

export function isReact18(): boolean {
return React.version.startsWith("18");
}
8 changes: 6 additions & 2 deletions packages/core/src/components/portal/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as ReactDOM from "react-dom";
import { Classes, DISPLAYNAME_PREFIX, type Props } from "../../common";
import type { ValidationMap } from "../../common/context";
import * as Errors from "../../common/errors";
import { isReact18 } from "../../common/utils/reactUtils";
import { PortalContext } from "../../context/portal/portalProvider";

export interface PortalProps extends Props {
Expand Down Expand Up @@ -155,8 +156,11 @@ export function Portal(
}

Portal.displayName = `${DISPLAYNAME_PREFIX}.Portal`;
// eslint-disable-next-line deprecation/deprecation
Portal.contextTypes = PORTAL_LEGACY_CONTEXT_TYPES;
// only use legacy context in React 16 or 17
if (!isReact18()) {
// eslint-disable-next-line deprecation/deprecation
Portal.contextTypes = PORTAL_LEGACY_CONTEXT_TYPES;
}

function maybeRemoveClass(classList: DOMTokenList, className?: string) {
if (className != null && className !== "") {
Expand Down

1 comment on commit a1fc694

@adidahiya
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core] break(Portal): stop using legacy context in React 18 (#6680)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.