@@ -80,6 +80,44 @@ describe("TimePicker", () => {
8080 expect ( resizeObserverCallback ) . toBe ( null ) ;
8181 } ) ;
8282 } ) ;
83+
84+ it ( "should not cause infinite loop when resize callback is called multiple times" , async ( ) => {
85+ const { container } = render (
86+ < DatePicker
87+ inline
88+ selected = { new Date ( ) }
89+ showTimeSelect
90+ timeIntervals = { 15 }
91+ /> ,
92+ ) ;
93+
94+ await waitFor ( ( ) => {
95+ expect ( mockObserve ) . toHaveBeenCalledTimes ( 1 ) ;
96+ } ) ;
97+
98+ const resizeObserverCallback = getResizeObserverCallback ( ) ;
99+ const mockObserveElement = mockObserve . mock . calls [ 0 ] [ 0 ] ;
100+ expect ( typeof resizeObserverCallback ) . toBe ( "function" ) ;
101+
102+ const timeList = container . querySelector (
103+ ".react-datepicker__time-list" ,
104+ ) as HTMLElement ;
105+ expect ( timeList ) . not . toBeNull ( ) ;
106+
107+ // Get initial height
108+ const initialHeight = timeList . style . height ;
109+
110+ // Call resize callback multiple times (simulating what would happen in an infinite loop)
111+ if ( resizeObserverCallback ) {
112+ resizeObserverCallback ( [ ] , mockObserveElement ) ;
113+ resizeObserverCallback ( [ ] , mockObserveElement ) ;
114+ resizeObserverCallback ( [ ] , mockObserveElement ) ;
115+ }
116+
117+ // Height should remain stable (not grow infinitely)
118+ // The fix ensures setState is only called when height actually changes
119+ expect ( timeList . style . height ) . toBe ( initialHeight ) ;
120+ } ) ;
83121 } ) ;
84122
85123 it ( "should update on input time change" , ( ) => {
0 commit comments