Skip to content

fix: [M3-7174] - Fix BarPercent console errors and other improvements#9716

Merged
bnussman-akamai merged 3 commits intolinode:developfrom
bnussman-akamai:M3-7174-fix-bar-percent-console-errors
Sep 26, 2023
Merged

fix: [M3-7174] - Fix BarPercent console errors and other improvements#9716
bnussman-akamai merged 3 commits intolinode:developfrom
bnussman-akamai:M3-7174-fix-bar-percent-console-errors

Conversation

@bnussman-akamai
Copy link
Member

@bnussman-akamai bnussman-akamai commented Sep 25, 2023

Description 📝

  • Fix some console errors and general issues with our BarPercent component 🛠️

Major Changes 🔄

  • Fix narrow prop getting passed to the underlying component
  • Fixed undefined className
  • Use named exports instead of default exports ✏️

Preview 📷

Before After
Screenshot 2023-09-25 at 10 47 49 AM Screenshot 2023-09-25 at 10 48 31 AM
Screenshot 2023-09-25 at 10 47 18 AM Screenshot 2023-09-25 at 10 46 55 AM

How to test 🧪

  • You can check storybook to verify the changes are okay
  • Alternatively, you can turn on the MSW and look in the notification menu (the component is used here)
  • Verify you don't see the console error shown in the screenshot above
  • Verify you don't see a undefined className
  • Verify the component works as expected (functionality should not have changed)

@bnussman-akamai bnussman-akamai requested a review from a team as a code owner September 25, 2023 15:02
@bnussman-akamai bnussman-akamai requested review from carrillo-erik and jdamore-linode and removed request for a team September 25, 2023 15:02
@mjac0bs mjac0bs self-requested a review September 25, 2023 15:25
@bnussman-akamai bnussman-akamai self-assigned this Sep 25, 2023
} = props;

return (
<StyledDiv className={`${className}`}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If className was undefined, this would actually write undefined to the DOM. This probably wasn't intended

const StyledLinearProgress = styled(LinearProgress, {
label: 'StyledLinearProgress',
shouldForwardProp: (prop) => isPropValid(['rounded'], prop),
shouldForwardProp: (prop) => isPropValid(['rounded', 'narrow'], prop),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the main console error

Copy link
Contributor

@mjac0bs mjac0bs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed VM12523:106 Warning: Received truefor a non-boolean attributenarrow. is no longer shown as a console warning for narrow BarPercent components. Confirmed no "undefined" in the console. Also confirmed that there were no unexpected regressions or console warnings for the BarPercents in the MNTP dialog or Linode Details > Network tab.

I did notice a few console warnings unrelated to BarPercent (mostly caused by NotificationSection) when testing this PR by turning on the mocks and checking the notification menu, so I created a follow up tech story ticket for that: M3-7180.

Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • no more console logs ✅
  • imports and storybook ✅

);
};

export default React.memo(BarPercent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it may be to trivial to remove the memoization if we assume the value changing often but curious to know your reasons. Those are micro optimisations but they add up in the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary reason for omitting it is just because I figured it was a micro optimisation. I'd be cool with adding it back.

I generally don't know the absolute best practice for cases like this. Here's the React docs about it https://react.dev/reference/react/memo#should-you-add-memo-everywhere

What would you reccomend in this situation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way i think about it (for React.memo specifically) is (will prob paraphrase a thousand sources):
"Is it more expensive to re-render or to compare props". If it re-renders all the time, then running a prop diff is worse than letting the component re-render every time cause we're adding overhead.

In this case i would keep it (it does not mean you have to, it's rather subjective here) cause in a lot of cases this component's props won't change that often so I don't think it hurts to prevent unnecessary re-rendering. The component is small and the performance impact is completely negligible by itself, but in the grand scheme of things every bit helps I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me. Thank you for the explanation! I'll re-add it and merge!

@bnussman-akamai bnussman-akamai merged commit 3fbd0e9 into linode:develop Sep 26, 2023
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.

4 participants