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

Cache locale dict lest child hooks always re-render

Open IgnusG opened this issue 1 year ago • 0 comments

Closes https://github.com/adobe/react-spectrum/issues/6184

The child hooks like useCalendarGrid etc. use useLocale to fetch their locale data.

As such whenever this context value changes these hooks (and the component they are part of are forced to re-render) even if nothing else is changed. Even if the locale doesn't change as long as I18nProvider renders (eg. as part of a parent component update) it creates a new dict which forces a re-render.

✅ Pull Request Checklist:

  • [X] Included link to corresponding React Spectrum GitHub Issue.
  • [ ] ~~Added/updated unit tests and storybook for this change (for new code or code which already has tests).~~
  • [X] Filled out test instructions.
  • [ ] ~~Updated documentation (if it already exists for this component).~~
  • [X] Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Perform the steps in https://github.com/adobe/react-spectrum/issues/6184 and observe the rendering of I18nProvider when locale doesn't change no longer causes renders inside of components using the calendar hooks.

IgnusG avatar Apr 11 '24 11:04 IgnusG