Skip to content

Commit

Permalink
Update React version check to support 18+ in Portal (#7137)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmpeeduwee authored Jan 12, 2025
1 parent 0a63583 commit 4909fc2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/core/changelog/@unreleased/pr-7137.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Update React version check in Portal component to support React 18 and newer versions.
links:
- https://github.com/palantir/blueprint/pull/7137
5 changes: 3 additions & 2 deletions packages/core/src/common/utils/reactUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function isElementOfType<P = {}>(
);
}

export function isReact18(): boolean {
return React.version.startsWith("18");
export function isReact18OrHigher(): boolean {
const majorVersion = parseInt(React.version.split(".")[0], 10);
return majorVersion >= 18;
}
4 changes: 2 additions & 2 deletions packages/core/src/components/portal/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +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 { isReact18OrHigher } from "../../common/utils/reactUtils";
import { PortalContext } from "../../context/portal/portalProvider";

export interface PortalProps extends Props {
Expand Down Expand Up @@ -157,7 +157,7 @@ export function Portal(

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

1 comment on commit 4909fc2

@svc-palantir-github
Copy link

Choose a reason for hiding this comment

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

Update React version check to support 18+ in Portal (#7137)

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.