From 5a046a3dab1d6dd97df48f21c128ad2f3be5b5dc Mon Sep 17 00:00:00 2001 From: Heising Date: Wed, 8 Nov 2023 13:57:42 +0800 Subject: [PATCH] fix(notification): fix Notification triggered for the first time in React 18 concurrent mode --- src/notification/NotificationList.tsx | 36 +++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/notification/NotificationList.tsx b/src/notification/NotificationList.tsx index 6c3cbf6b2a..fffe5b20e4 100644 --- a/src/notification/NotificationList.tsx +++ b/src/notification/NotificationList.tsx @@ -1,4 +1,5 @@ import React, { forwardRef, useImperativeHandle, useState, useEffect } from 'react'; +import { flushSync } from 'react-dom'; import { render } from '../_util/react-render'; import useConfig from '../hooks/useConfig'; import { @@ -132,20 +133,23 @@ export const fetchListInstance = ( zIndex: number, ): Promise => new Promise((resolve) => { - if (listMap.has(placement)) { - resolve(listMap.get(placement)); - } else { - render( - { - listMap.set(placement, instance); - resolve(instance); - }} - />, - attach, - ); - } + // Fix the bug of Notification triggered for the first time in React 18 concurrent mode + flushSync(() => { + if (listMap.has(placement)) { + resolve(listMap.get(placement)); + } else { + render( + { + listMap.set(placement, instance); + resolve(instance); + }} + />, + attach, + ); + } + }); });