Skip to content

Commit

Permalink
#2072 fix: added explicit check for react version (#2114)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Anderson [email protected]
Signed-off-by: Sean Anderson <[email protected]>
  • Loading branch information
sean-anderson-ibm authored Aug 22, 2024
1 parent d73fff1 commit 49221c5
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default class SvgCanvasExternal {
return React.isValidElement(el);
}

isReact18OrHigher() {
return Number(React.version.split(".")[0]) >= 18;
}

addNodeExternalObject(node, i, foreignObjects) {
const jsx = (
<node.layout.nodeExternalObject
Expand All @@ -51,7 +55,7 @@ export default class SvgCanvasExternal {

renderExternalObject(jsx, container) {
// createRoot only available in React v18
if (createRoot) {
if (this.isReact18OrHigher()) {
if (!container.ccExtRoot) {
container.ccExtRoot = createRoot(container);
}
Expand All @@ -65,7 +69,7 @@ export default class SvgCanvasExternal {

removeExternalObject(obj, i, foreignObjects) {
// createRoot only available in React v18
if (createRoot) {
if (this.isReact18OrHigher()) {
const container = foreignObjects[i];
if (!container.ccExtRoot) {
container.ccExtRoot = createRoot(container);
Expand Down

0 comments on commit 49221c5

Please sign in to comment.