dhis2 / ui

Components and related resources for the DHIS2 design system
https://ui.dhis2.nu
BSD 3-Clause "New" or "Revised" License
40 stars 15 forks source link

fix: update default props to JS default params #1598

Closed kabaros closed 1 month ago

kabaros commented 1 month ago

Implements LIBS-682

As we move to React 18 in platform as part ofhttps://github.com/dhis2/app-platform/pull/876, all our components and apps need to stop using defaultProps as these were deprecated and started generating a warning since React 18.3.

Most of this transformation was done using a codemod - the codemod is a bit brittle and tied to this project for now, but can be made more generic and incorporated in d2 migrate as we test it in more projects.

dhis2-bot commented 1 month ago

🚀 Deployed on https://pr-1598--dhis2-ui.netlify.app

KaiVandivier commented 1 month ago

Worked with @amcgee and found that the tests that were hanging were ones using Popper components, and then discovered that the default modifiers = [] param was creating a new array on each rerender, which triggered a useMemo recomputation since it's a dependency, which caused a render loop

Setting the prop default to a stable object reference fixed the loop issue, which was manually noticeable in storybook stories, so we updated other default props to similar stable objects -- running tests now to see if they work 🤞

Update: Select and Popper tests work for me locally now, but I haven't run the whole test suite... cypress caused a stack overflow when I tried to do that 😞

kabaros commented 1 month ago

great find! thanks @amcgee @KaiVandivier

dhis2-bot commented 1 month ago

:tada: This PR is included in version 9.11.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: