11import { clsx } from 'clsx' ;
22import KeyCode from '@rc-component/util/lib/KeyCode' ;
3+ import warning from '@rc-component/util/lib/warning' ;
34import * as React from 'react' ;
45import type { NoticeConfig } from './interface' ;
56import pickAttrs from '@rc-component/util/lib/pickAttrs' ;
67
8+ /**
9+ * Maximum delay value for setTimeout in seconds (2^31 - 1 ms).
10+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value
11+ */
12+ const MAX_DURATION = 2147483647 / 1000 ;
13+
714export interface NoticeProps extends Omit < NoticeConfig , 'onClose' > {
815 prefixCls : string ;
916 className ?: string ;
@@ -38,7 +45,9 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
3845 const [ percent , setPercent ] = React . useState ( 0 ) ;
3946 const [ spentTime , setSpentTime ] = React . useState ( 0 ) ;
4047 const mergedHovering = forcedHovering || hovering ;
41- const mergedDuration : number = typeof duration === 'number' ? duration : 0 ;
48+
49+ const rawDuration : number = typeof duration === 'number' ? duration : 0 ;
50+ const mergedDuration : number = Math . min ( rawDuration , MAX_DURATION ) ;
4251 const mergedShowProgress = mergedDuration > 0 && showProgress ;
4352
4453 // ======================== Close =========================
@@ -52,6 +61,14 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
5261 }
5362 } ;
5463
64+ // ========================= Warn =========================
65+ React . useEffect ( ( ) => {
66+ warning (
67+ rawDuration <= MAX_DURATION ,
68+ `\`duration\` exceeds the maximum supported value (${ MAX_DURATION } s) and has been clamped.` ,
69+ ) ;
70+ } , [ rawDuration ] ) ;
71+
5572 // ======================== Effect ========================
5673 React . useEffect ( ( ) => {
5774 if ( ! mergedHovering && mergedDuration > 0 ) {
0 commit comments