Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove defaultProps usages for functional components #7224

Open
wants to merge 60 commits into
base: react-18.3.0-upgrade
Choose a base branch
from

Conversation

undeletable
Copy link
Contributor

@undeletable undeletable commented May 9, 2024

What does this PR do?

Starting from React 19, defaultProps for functional components is deprecated. Starting from React 18.3, the corresponding error is thrown for a functional component with defaultProps defined.

Changes in this PR:

  • replace defaultProps for functional components with default function parameters values;
  • use attrs method of styled-components to pass theme to styled components which might be outside of theme context (required per remove defaultProps from Grommet #6741 (comment));
  • add custom hook to obtain theme from context with fallback to default value;
  • configure eslint rule to not require defaultProps for functional components;
  • update snapshots.

Where should the reviewer start?

No specific place to start.

What testing has been done on this PR?

  • manual testing on storybook and real project using grommet;
  • tests run result:
Test Suites: 97 passed, 97 total
Tests:       1548 passed, 1548 total
Snapshots:   1777 passed, 1777 total

How should this be manually tested?

Use React 18.3+ in an app. Check that styles are applied correctly and no errors about defaultProps are thrown into console.

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

React 19 upgrade guide

What are the relevant issues?

Closes #6741

Screenshots (if appropriate)

N/A.

Do the grommet docs need to be updated?

Just the internal ones (if any).

Should this PR be mentioned in the release notes?

Yes.

Is this change backwards compatible or is it a breaking change?

Changes are backwards compatible.

Signed-off-by: Max Shepel <max@undeletable.name>
Signed-off-by: Max Shepel <max@undeletable.name>
undeletable and others added 5 commits June 4, 2024 13:26
Signed-off-by: Max Shepel <max@undeletable.name>
…parameter value

Signed-off-by: Max Shepel <max@undeletable.name>
* fix: Storybook - RangeInput/Bounds example

* feedback: use usEeffect for disable buttons

* feedback: use usEeffect for disable buttons

* fix: lint fix
@britt6612
Copy link
Collaborator

britt6612 commented Jun 6, 2024

@undeletable
Hey I was looking over this PR and Im glad to see that you caught Pagination in that it is throwing an error with not wrapped in <grommet> wrapper so I went ahead and added tests for the components on which other components also have this issue and found quite a few I was wondering if you would be open to fixing these and adding the attrs to these components
List ToggleGroup DataChart NameValueList RangeSelector WorldMap FileInput``PageHeader StarRating
These are just a few there are a few more.

#7249

@undeletable
Copy link
Contributor Author

@britt6612 Pagination tests fail sometimes because of different reason (slowness), but I got your point. I'll take a look.

@undeletable
Copy link
Contributor Author

undeletable commented Jun 7, 2024

@jcfilben @britt6612 I've noticed that target branch in #7249 is different from master. Should I change target branch to react-18.3.0-upgrade in my PR?

@undeletable
Copy link
Contributor Author

@britt6612 I've added fallbacks to default theme to all the remaining places I saw that might be needed. Tests on both my and your branch passed.

…b@users.noreply.github.com>

On behalf of Basith <134603758+abdulbasithqb@users.noreply.github.com>, I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: 2a4e9ac

Signed-off-by: Max Shepel <max@undeletable.name>
…rchibeque@Brittanys-MBP-2.home>

On behalf of Brittany Archibeque <brittanyarchibeque@Brittanys-MBP-2.home>, I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: a954793
On behalf of Brittany Archibeque <brittanyarchibeque@Brittanys-MBP-2.home>, I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: f492adb
On behalf of Brittany Archibeque <brittanyarchibeque@Brittanys-MBP-2.home>, I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: 3fd3a11

Signed-off-by: Max Shepel <max@undeletable.name>
…ben@users.noreply.github.com>

On behalf of Jessica Filben <54560994+jcfilben@users.noreply.github.com>, I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: 60d5ece

Signed-off-by: Max Shepel <max@undeletable.name>
I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: a1a5a03
I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: a092b71
I, Max Shepel <max@undeletable.name>, hereby add my Signed-off-by to this commit: fa50a41

Signed-off-by: Max Shepel <max@undeletable.name>
@britt6612
Copy link
Collaborator

@jcfilben @britt6612 I've noticed that target branch in #7249 is different from master. Should I change target branch to react-18.3.0-upgrade in my PR?

@undeletable so yes what I did was make that new PR which will get merged into react-18.3.0-upgrade then we will point your PR to react-18.3.0-upgrade that way we can make sure tests are good before merging to master!

Thank you for adding this for the rest of the components

@undeletable undeletable changed the base branch from master to react-18.3.0-upgrade June 7, 2024 18:31
@undeletable
Copy link
Contributor Author

@britt6612 I've changed base branch to react-18.3.0-upgrade, will keep the PR in sync with it

@britt6612
Copy link
Collaborator

@undeletable thank you! Hoping my PR gets merged early next week! then we can merge yours!

@undeletable undeletable mentioned this pull request Jun 7, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove defaultProps from Grommet
5 participants