-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[material-ui][Badge] Fix stale values being used when badge is invisible #43083
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
base: master
Are you sure you want to change the base?
Conversation
Netlify deploy previewhttps://deploy-preview-43083--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
@@ -134,7 +134,7 @@ describe('<Badge />', () => { | |||
it('should render with invisible class when invisible and showZero are set to false and content is 0', () => { | |||
const { container } = render(<Badge badgeContent={0} showZero={false} invisible={false} />); | |||
expect(findBadge(container)).to.have.class(classes.invisible); | |||
expect(findBadge(container)).to.have.text(''); | |||
expect(findBadge(container)).to.have.text('0'); |
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.
This reverts the fix introduced in #21557. This fix has added the usage of the usePreviousProps
hook. You will noticed on this demo: https://next.mui.com/material-ui/react-badge/#badge-visibility, that when clicking on the "-" button, when the value is 1, it immediately disappears without adding the "0" as a content - this is a non valid state. The issue is again here on this PR deploy preview.
I would recommend when going trough history to search for the PR that did the fix, as it is usually how you can understand the motivation for the code change, e.g. #21557 has a description & explanation. Also, changing a test should be an indication that something will be broken/behavior will change. |
Fixes: #43081
To see the error:
.MuiBadge-badge
element.MuiBadge-badge
element's valueBefore: https://stackblitz.com/edit/react-qkjzbj?file=Demo.tsx
After: Waiting for CI build
I think the use of
usePreviousProps
is incorrect, asbadgeContent
,max
anddisplayValue
shouldn't be coupled with theinvisible
value. They should always be updated regardless. It was originally added for another use case: mnajdova@7572c90#diff-26877d58ee4ebaa271700aae39d84f0ce250e8d01c677024bbf0d53f46159b1b, so it might've stuck around inadvertently.I fixed in both
mui-material
andmui-base
for consistency.