-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: master
Are you sure you want to change the base?
Conversation
@undeletable Thank you for your contribution! We are in the process of looking at this just wanted to let you know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
In the changes I saw that you are using the attrs
method of styled-components to pass the theme. In the PR notes you referenced this comment #6741 (comment) as the reason for those changes. I think this comment was misinterpreting the original intent of removing defaultProps
.
There is some confusing naming where we have defaultProps
in the react sense and then we have defaultProps
in Grommet that contains the base theme. I think #6741 (comment), misunderstood the issue and was thinking that we would remove the defaultProps
that has the Grommet theme instead of removing the react defaultProps
.
All this to say I don't think the comment is relevant for what we are trying to do here with removing the react defaultProps and we don't need to use the attrs
method.
We did also test to confirm that the base theme is being passed through correctly to components that are not in a Grommet wrapper in react 18.3.0 without using attrs
.
Actually these two entities are connected: Grommet's Another hint for me was that component snapshots are way too different without both React's |
@jcfilben Way 1. Using inside the component function:
Here, the case of using component outside of theme context is handled by using fallback vaue.No need to pass theme as default prop. I just externalized this logic in the custom hook. Way 2. Using inside arguments of styled-components' template function:
Here, the case of using component outside of theme context is handled by passing theme as default prop. So, if Also, I've tried to remove all Please correct me if I'm wrong. |
I, Max Shepel <[email protected]>, hereby add my Signed-off-by to this commit: 6cc1019 I, Max Shepel <[email protected]>, hereby add my Signed-off-by to this commit: 429627c I, Max Shepel <[email protected]>, hereby add my Signed-off-by to this commit: 5c80f67 Signed-off-by: Max Shepel <[email protected]>
Thanks for the explanation, and sorry for the confusion on my end. Yesterday my team and I had tested in storybook by removing the Grommet wrapper and
I think the direction you've taken with |
Signed-off-by: Max Shepel <[email protected]>
If you update your branch with the latest changes from the master branch, the chromatic check should pass |
@jcfilben Thanks for the suggestion, but this branch is up-to-date with master, and chromatic is still failing. The error is 'Missing project token' - I believe that's because I haven't set up one for the fork. |
Hmm you shouldn't need to set anything up on your end, the chromatic token should be accessible from grommet forks when they run on circleci. I'll look into what might be going wrong here |
I'm going to try and push a no-op commit to your PR to see if I can re-trigger the chromatic step on circleci edit: locally when I pull down this PR I have some tests failing, so I didn't end up pushing anything up yet |
For me, some tests for Pagination are slowly running locally - both in master and my branch. I haven't checked yet what's causing the slowness. |
@jcfilben
|
@jcfilben On my local env the following test is failing almost always:
Thrown error:
Comparing to other tests in at least that module, there are many actions performed inside this one. Looks like this is the cause. |
Hey @undeletable thanks for looking into this, we manually enabled the option so that we are passing the chromatic token to forked PR builds a few months ago so we should be good there. This has been working for other forked PRs but strangely not for this PR. For the tests I am getting snapshot changes locally. I'm seeing if someone else on my team can run this locally to see if it is just something in my environment or if they are running into this as well. |
If I remember correctly, I was facing this several months ago after using npm for installing dependencies and running tests. When I use yarn, everything's fine (seeing yarn.lock in the repo, I assume this is expected).
I'm not sure if it matters, but my fork was created prior to that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why this snapshot is changing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about that yet. In fact, the changes are about reordering styles and removing the following one:
.c8:hover {
box-shadow: 0px 0px 0px 2px #7D4CDB;
}
I'll check why that happens and if that's expected
@@ -49,7 +49,7 @@ describe('Menu', () => { | |||
test('should have no accessibility violations', async () => { | |||
const { container } = render( | |||
<Grommet> | |||
<Menu /> | |||
<Menu items={[]} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this change? Shouldn't Menu items = []
by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment I've added it, using Menu
with no items
prop passed resulted in test failure. I'll check if that's still the case and why, if yes.
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 withdefaultProps
defined.Changes in this PR:
defaultProps
for functional components with default function parameters values;attrs
method ofstyled-components
to pass theme to styled components which might be outside of theme context (required per remove defaultProps from Grommet #6741 (comment));defaultProps
for functional components;Where should the reviewer start?
No specific place to start.
What testing has been done on this PR?
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.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.