@@ -50,7 +50,9 @@ export interface NotificationProps {
5050
5151interface NotificationState {
5252 notices : {
53- notice : NoticeContent ;
53+ notice : NoticeContent & {
54+ userPassKey ?: React . Key ;
55+ } ;
5456 holderCallback ?: HolderReadyCallback ;
5557 } [ ] ;
5658}
@@ -87,11 +89,14 @@ class Notification extends Component<NotificationProps, NotificationState> {
8789
8890 add = ( originNotice : NoticeContent , holderCallback ?: HolderReadyCallback ) => {
8991 const key = originNotice . key || getUuid ( ) ;
90- const notice = { ...originNotice , key } ;
92+ const notice : NoticeContent & { key : React . Key ; userPassKey ?: React . Key } = {
93+ ...originNotice ,
94+ key,
95+ } ;
9196 const { maxCount } = this . props ;
92- this . setState ( previousState => {
97+ this . setState ( ( previousState ) => {
9398 const { notices } = previousState ;
94- const noticeIndex = notices . map ( v => v . notice . key ) . indexOf ( key ) ;
99+ const noticeIndex = notices . map ( ( v ) => v . notice . key ) . indexOf ( key ) ;
95100 const updatedNotices = notices . concat ( ) ;
96101 if ( noticeIndex !== - 1 ) {
97102 updatedNotices . splice ( noticeIndex , 1 , { notice, holderCallback } ) ;
@@ -107,6 +112,12 @@ class Notification extends Component<NotificationProps, NotificationState> {
107112 // https://github.com/react-component/notification/commit/32299e6be396f94040bfa82517eea940db947ece
108113 notice . key = updatedNotices [ 0 ] . notice . key ;
109114 notice . updateMark = getUuid ( ) ;
115+
116+ // zombieJ: That's why. User may close by key directly.
117+ // We need record this but not re-render to avoid upper issue
118+ // https://github.com/react-component/notification/issues/129
119+ notice . userPassKey = key ;
120+
110121 updatedNotices . shift ( ) ;
111122 }
112123 updatedNotices . push ( { notice, holderCallback } ) ;
@@ -117,9 +128,12 @@ class Notification extends Component<NotificationProps, NotificationState> {
117128 } ) ;
118129 } ;
119130
120- remove = ( key : React . Key ) => {
131+ remove = ( removeKey : React . Key ) => {
121132 this . setState ( ( { notices } ) => ( {
122- notices : notices . filter ( ( { notice } ) => notice . key !== key ) ,
133+ notices : notices . filter ( ( { notice : { key, userPassKey } } ) => {
134+ const mergedKey = userPassKey || key ;
135+ return mergedKey !== removeKey ;
136+ } ) ,
123137 } ) ) ;
124138 } ;
125139
@@ -181,7 +195,7 @@ class Notification extends Component<NotificationProps, NotificationState> {
181195 key = { key }
182196 className = { classNames ( motionClassName , `${ prefixCls } -hook-holder` ) }
183197 style = { { ...motionStyle } }
184- ref = { div => {
198+ ref = { ( div ) => {
185199 if ( typeof key === 'undefined' ) {
186200 return ;
187201 }
0 commit comments