gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.
https://daypicker.dev
MIT License
5.86k stars 700 forks source link

Still a lot of re-renders in v9 #2222

Open ArthurGoupil opened 6 days ago

ArthurGoupil commented 6 days ago

Description

Hello!

I was following this issue for quite a long time https://github.com/gpbl/react-day-picker/issues/1473 and was happy to see it has been potentially fixed in v9.

From my first tests, it looks like when selecting a date, it still re-renders every days of every months:

https://github.com/gpbl/react-day-picker/assets/50388474/d7d0b109-834a-4e67-8c1b-88f7dd5ef129

Here is the related sandbox

Am I missing something in the basic implementation or so?

Thanks a lot!

Expected Behavior

It does not re-render every days when not necessary.

gpbl commented 6 days ago

Hey @ArthurGoupil, thanks for the heads up and for testing v9.

The rerender is necessary to manage focus: when a day is clicked, the other cells need to know if they should become the "possible focus target."

We may explore other ways to handle focus, but they are challenging to implement following React patterns.

I believe the rerendering shouldn't be too concerning. I've moved out some of the calculations that made rerendering slow in the previous version. There are some upcoming changes that will further memoize the values used by DayPicker, thus reducing other unnecessary rerenders.

ArthurGoupil commented 5 days ago

Alright thanks a lot for the answer @gpbl 🙏