From af2d1a8bc4caf12a41110989bc29e756465c0373 Mon Sep 17 00:00:00 2001 From: Haixing <65376724+HaixingOoO@users.noreply.github.com> Date: Mon, 24 Feb 2025 14:32:23 +0800 Subject: [PATCH] fix(react-render): fix React19 reactRender error (#3380) --- src/_util/react-render.ts | 6 +++++- src/notification/NotificationList.tsx | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/_util/react-render.ts b/src/_util/react-render.ts index 7ce1dd6d01..0fdbcd7ba5 100644 --- a/src/_util/react-render.ts +++ b/src/_util/react-render.ts @@ -2,6 +2,7 @@ // @ts-ignore import type * as React from 'react'; import * as ReactDOM from 'react-dom'; +import { createRoot as createRootClient } from 'react-dom/client'; import type { Root } from 'react-dom/client'; // Let compiler not to search module usage @@ -16,13 +17,16 @@ const fullClone = { type CreateRoot = (container: ContainerType) => Root; +// @ts-ignore const { version, render: reactRender, unmountComponentAtNode } = fullClone; let createRoot: CreateRoot; try { const mainVersion = Number((version || '').split('.')[0]); - if (mainVersion >= 18) { + if (mainVersion >= 18 && mainVersion < 19) { ({ createRoot } = fullClone); + } else if (mainVersion >= 19) { + createRoot = createRootClient; } } catch (e) { // Do nothing; diff --git a/src/notification/NotificationList.tsx b/src/notification/NotificationList.tsx index e1389579a9..cba8affce1 100644 --- a/src/notification/NotificationList.tsx +++ b/src/notification/NotificationList.tsx @@ -110,8 +110,8 @@ const NotificationList = forwardRef { remove(props.key); onDurationEnd();