-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[material-ui][Avatar] Improve fallback when children
is empty string or boolean
#40766
Conversation
Netlify deploy previewhttps://deploy-preview-40766--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
@oliviertassinari hello I found an example of how you handle expected errors here: BTW |
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.
Should I remove the test or extend it so that we expect a console error? If the last is correct, could you reference how similar cases were handled in the codebase?
We should remove the test. It's not needed. The PropType warning is likely because true
is not a valid React node for the children prop, unlike strings or null. React considers false
as a valid React node, rendering nothing.
children
is empty string
Done |
children
is empty stringchildren
is empty string or boolean
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.
Looks good!
} else if (childrenProp != null) { | ||
} else if (childrenProp != null && childrenProp !== '' && typeof childrenProp !== 'boolean') { |
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 think we can shorten the condition without making any test fail: #40834.
…g or boolean (mui#40766) Co-authored-by: ZeeshanTamboli <[email protected]>
Hey! We've been discussing this change at #41291. You might want to check that out and join the discussion. |
I faced an unexpected behavior when our BE service didn't return a valid image URL, and my
Avatar
component showed me an empty circle with a background. After a quick investigation, I found that we may pass both a URL and children as a fallback in some cases in the project. If both of them are falsy, from the UX perspective, it leads to unexpected results, at least according to the current documentation.You can check it in the current version of the library with the following code snippet.
I don't see any reason why this slight quality-of-life improvement could be wrong, but I gladly accept any feedback.