react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

the package may crash application under certain conditions

Open nikolasbo opened this issue 2 years ago • 0 comments

We have noticed that the crash may occur when changing the timezones. Occurs when opening Time picker, and based on the code in time.jsx, line 181-184: This condition may not execute, leaving class variable <this.centerLi> as undefined. if (isBefore(time, activeTime) || isEqual(time, activeTime)) { this.centerLi = li; }

and then it's being passed as undefined to this method: static calcCenterPosition = (listHeight, centerLiRef) => { return ( centerLiRef.offsetTop - (listHeight / 2 - centerLiRef.clientHeight / 2) ); };,

which crashes the application with message: react-datepicker.min.js:3463 Uncaught TypeError: Cannot read properties of undefined (reading 'offsetTop') at Function.calcCenterPosition (react-datepicker.min.js:3463:1)

Screen Shot 2022-08-15 at 10 19 30 AM

Adding optionals, seems to be fixing the issue of APP crash. static calcCenterPosition = (listHeight, centerLiRef) => { return ( centerLiRef?.offsetTop - (listHeight / 2 - centerLiRef?.clientHeight / 2) ); };

We have tested on latest versions of Chrome, Safari and Firefox.

The PR with proposed fix is here: https://github.com/Hacker0x01/react-datepicker/pull/3702

nikolasbo avatar Aug 15 '22 18:08 nikolasbo