@@ -18,7 +18,7 @@ function getUuid() {
1818export interface NoticeContent extends Omit < NoticeProps , 'prefixCls' | 'children' > {
1919 prefixCls ?: string ;
2020 key ?: React . Key ;
21- updateKey ?: React . Key ;
21+ updateMark ?: string ;
2222 content ?: React . ReactNode ;
2323}
2424
@@ -84,10 +84,9 @@ class Notification extends Component<NotificationProps, NotificationState> {
8484 return transitionName ;
8585 }
8686
87- add = ( notice : NoticeContent , holderCallback ?: HolderReadyCallback ) => {
88- // eslint-disable-next-line no-param-reassign
89- notice . key = notice . key || getUuid ( ) ;
90- const { key } = notice ;
87+ add = ( originNotice : NoticeContent , holderCallback ?: HolderReadyCallback ) => {
88+ const key = originNotice . key || getUuid ( ) ;
89+ const notice = { ...originNotice , key } ;
9190 const { maxCount } = this . props ;
9291 this . setState ( previousState => {
9392 const { notices } = previousState ;
@@ -101,7 +100,12 @@ class Notification extends Component<NotificationProps, NotificationState> {
101100 // instead of remove and mount). Same key was used before for both a) external
102101 // manual control and b) internal react 'key' prop , which is not that good.
103102 // eslint-disable-next-line no-param-reassign
104- notice . updateKey = updatedNotices [ 0 ] . notice . updateKey || updatedNotices [ 0 ] . notice . key ;
103+
104+ // zombieJ: Not know why use `updateKey`. This makes Notice infinite loop in jest.
105+ // Change to `updateMark` for compare instead.
106+ // https://github.com/react-component/notification/commit/32299e6be396f94040bfa82517eea940db947ece
107+ notice . key = updatedNotices [ 0 ] . notice . key ;
108+ notice . updateMark = getUuid ( ) ;
105109 updatedNotices . shift ( ) ;
106110 }
107111 updatedNotices . push ( { notice, holderCallback } ) ;
@@ -135,21 +139,18 @@ class Notification extends Component<NotificationProps, NotificationState> {
135139 const noticeKeys : React . Key [ ] = [ ] ;
136140
137141 notices . forEach ( ( { notice, holderCallback } , index ) => {
138- const update = Boolean ( index === notices . length - 1 && notice . updateKey ) ;
139- const key = notice . updateKey ? notice . updateKey : notice . key ;
142+ const updateMark = index === notices . length - 1 ? notice . updateMark : undefined ;
143+ const { key } = notice ;
140144
141- const onClose = createChainedFunction (
142- this . remove . bind ( this , notice . key ! ) ,
143- notice . onClose ,
144- ) as any ;
145+ const onClose = createChainedFunction ( this . remove . bind ( this , key ) , notice . onClose ) as any ;
145146
146147 const noticeProps = {
147148 prefixCls,
148149 closeIcon,
149150 ...notice ,
150151 ...notice . props ,
151152 key,
152- update ,
153+ updateMark ,
153154 onClose,
154155 onClick : notice . onClick ,
155156 children : notice . content ,
0 commit comments