react-day-picker icon indicating copy to clipboard operation
react-day-picker copied to clipboard

Bug: "Maximum call stack size exceeded" when navigating past the allowable range

Open jdelStrother opened this issue 3 years ago • 1 comments

Bug description

Using the keyboard to move outside of the range of enabled days results in an infinite loop as getNextDayFocus tries to find the next selectable day, eventually crashing with a stack error:

analytics:12 Uncaught RangeError: Maximum call stack size exceeded
    at isMatch (vendors-node_modules_react-day-picker_dist_index_esm_js-node_modules_react-popper_lib_esm_use-50aa90.chunk.js:9490:17)
    at vendors-node_modules_react-day-picker_dist_index_esm_js-node_modules_react-popper_lib_esm_use-50aa90.chunk.js:9533:13
    at Array.reduce (<anonymous>)
    at getActiveModifiers (vendors-node_modules_react-day-picker_dist_index_esm_js-node_modules_react-popper_lib_esm_use-50aa90.chunk.js:9531:51)
    at getNextFocus (vendors-node_modules_react-day-picker_dist_index_esm_js-node_modules_react-popper_lib_esm_use-50aa90.chunk.js:9601:31)
    at getNextFocus (vendors-node_modules_react-day-picker_dist_index_esm_js-node_modules_react-popper_lib_esm_use-50aa90.chunk.js:9604:20)
...
image

To reproduce

https://codesandbox.io/s/react-daypicker-forked-5zxg66?file=/src/App.tsx

Steps

  1. Visit the above sandbox, get keyboard focus into the day-picker with tab
  2. Move past the current date with arrow keys.
  3. Notice that Safari javascript locks up entirely, or Chrome throws a stack error.

Expected behavior

Anything but an infinite loop. It's not entirely straightforward to fix though, given the disabled prop can be used to return arbitrary disabled/enabled dates. (Who knows, maybe every day is supposed to be disabled except for 2500-01-01, better keep trying future dates...) Maybe getNextFocus should just bail if it gets more than 30 days ahead of the initial date?

jdelStrother avatar Sep 07 '22 16:09 jdelStrother

I put up a PR with a limit on recursion #1549

I have a few questions: how many days should we limit the recursion to? Also the approach is something I spun up around 1 AM while not sleeping, so it may be wonky. But it does seem to work well.

eXamadeus avatar Sep 09 '22 05:09 eXamadeus