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

Refactor Avatar to remove mergeProps #19449

Merged
merged 32 commits into from
Sep 24, 2021

Conversation

behowell
Copy link
Contributor

@behowell behowell commented Aug 19, 2021

Pull request checklist

Description of changes

Refactor AvatarProps, AvatarState, etc., and update useAvatar and renderAvatar to use the new approach described in RFC #18642

@fabricteam
Copy link
Collaborator

fabricteam commented Aug 19, 2021

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-avatar
Avatar
55.541 kB
15.32 kB
56.702 kB
15.741 kB
-1.161 kB
-421 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-badge
Badge
23.911 kB
7.038 kB
react-badge
CounterBadge
26.901 kB
7.752 kB
react-badge
PresenseBadge
237 B
177 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
164.715 kB
46.961 kB
react-components
react-components: FluentProvider & webLightTheme
35.769 kB
11.404 kB
🤖 This report was generated against 3df6452369ad5b6a9c83b58556208db710accb03

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 19, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 439ce8b:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor
Copy link

size-auditor bot commented Aug 19, 2021

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 3df6452369ad5b6a9c83b58556208db710accb03 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Aug 19, 2021

Perf Analysis (@fluentui/react)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 910 921 5000
BaseButton mount 894 887 5000
Breadcrumb mount 2671 2634 1000
ButtonNext mount 468 474 5000
Checkbox mount 1572 1512 5000
CheckboxBase mount 1276 1290 5000
ChoiceGroup mount 4753 4725 5000
ComboBox mount 1009 1013 1000
CommandBar mount 10309 10267 1000
ContextualMenu mount 6662 6452 1000
DefaultButton mount 1137 1131 5000
DetailsRow mount 3705 3795 5000
DetailsRowFast mount 3770 3694 5000
DetailsRowNoStyles mount 3626 3565 5000
Dialog mount 2447 2453 1000
DocumentCardTitle mount 142 140 1000
Dropdown mount 3241 3235 5000
FluentProviderNext mount 7541 7561 5000
FluentProviderWithTheme mount 367 349 10
FluentProviderWithTheme virtual-rerender 100 114 10
FluentProviderWithTheme virtual-rerender-with-unmount 485 487 10
FocusTrapZone mount 1770 1814 5000
FocusZone mount 1802 1789 5000
IconButton mount 1753 1741 5000
Label mount 335 333 5000
Layer mount 2958 2970 5000
Link mount 481 476 5000
MakeStyles mount 1862 1853 50000
MenuButton mount 1476 1502 5000
MessageBar mount 2021 2031 5000
Nav mount 3293 3344 1000
OverflowSet mount 1098 1105 5000
Panel mount 2356 2365 1000
Persona mount 831 843 1000
Pivot mount 1449 1416 1000
PrimaryButton mount 1274 1274 5000
Rating mount 7795 7649 5000
SearchBox mount 1304 1353 5000
Shimmer mount 2580 2578 5000
Slider mount 1982 1938 5000
SpinButton mount 5078 5032 5000
Spinner mount 426 421 5000
SplitButton mount 3210 3230 5000
Stack mount 502 519 5000
StackWithIntrinsicChildren mount 1671 1670 5000
StackWithTextChildren mount 4692 4672 5000
SwatchColorPicker mount 10554 10518 5000
Tabs mount 1450 1413 1000
TagPicker mount 2657 2703 5000
TeachingBubble mount 13369 13400 5000
Text mount 421 441 5000
TextField mount 1373 1378 5000
ThemeProvider mount 1179 1182 5000
ThemeProvider virtual-rerender 616 605 5000
ThemeProvider virtual-rerender-with-unmount 1909 1894 5000
Toggle mount 803 791 5000
buttonNative mount 121 109 5000

Perf Analysis (@fluentui/react-northstar)

Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
AttachmentMinimalPerf.default 169 148 1.14:1
RefMinimalPerf.default 263 237 1.11:1
FlexMinimalPerf.default 312 289 1.08:1
SkeletonMinimalPerf.default 378 350 1.08:1
ButtonMinimalPerf.default 181 169 1.07:1
AnimationMinimalPerf.default 428 402 1.06:1
VideoMinimalPerf.default 655 622 1.05:1
AvatarMinimalPerf.default 200 192 1.04:1
ButtonSlotsPerf.default 564 543 1.04:1
StatusMinimalPerf.default 695 671 1.04:1
CarouselMinimalPerf.default 477 464 1.03:1
GridMinimalPerf.default 342 332 1.03:1
ListCommonPerf.default 647 626 1.03:1
ListNestedPerf.default 559 544 1.03:1
ListWith60ListItems.default 654 638 1.03:1
LoaderMinimalPerf.default 727 708 1.03:1
RadioGroupMinimalPerf.default 450 438 1.03:1
SegmentMinimalPerf.default 349 339 1.03:1
ChatMinimalPerf.default 667 651 1.02:1
DialogMinimalPerf.default 764 752 1.02:1
ItemLayoutMinimalPerf.default 1248 1219 1.02:1
ProviderMinimalPerf.default 1136 1109 1.02:1
AlertMinimalPerf.default 274 272 1.01:1
BoxMinimalPerf.default 348 344 1.01:1
ChatDuplicateMessagesPerf.default 301 297 1.01:1
DividerMinimalPerf.default 374 372 1.01:1
EmbedMinimalPerf.default 4340 4291 1.01:1
HeaderMinimalPerf.default 353 351 1.01:1
LayoutMinimalPerf.default 375 372 1.01:1
MenuButtonMinimalPerf.default 1655 1638 1.01:1
PortalMinimalPerf.default 182 181 1.01:1
SliderMinimalPerf.default 1727 1702 1.01:1
SplitButtonMinimalPerf.default 4296 4245 1.01:1
TableManyItemsPerf.default 1889 1872 1.01:1
DatepickerMinimalPerf.default 5481 5503 1:1
DropdownMinimalPerf.default 3279 3285 1:1
HeaderSlotsPerf.default 754 753 1:1
ListMinimalPerf.default 512 510 1:1
MenuMinimalPerf.default 842 844 1:1
PopupMinimalPerf.default 589 590 1:1
TableMinimalPerf.default 394 394 1:1
CustomToolbarPrototype.default 4137 4143 1:1
TooltipMinimalPerf.default 1015 1016 1:1
AttachmentSlotsPerf.default 1081 1093 0.99:1
CardMinimalPerf.default 546 550 0.99:1
CheckboxMinimalPerf.default 2757 2786 0.99:1
ImageMinimalPerf.default 372 375 0.99:1
InputMinimalPerf.default 1316 1333 0.99:1
RosterPerf.default 1185 1200 0.99:1
TextMinimalPerf.default 352 354 0.99:1
TextAreaMinimalPerf.default 497 502 0.99:1
TreeMinimalPerf.default 796 806 0.99:1
FormMinimalPerf.default 389 398 0.98:1
IconMinimalPerf.default 614 629 0.98:1
TreeWith60ListItems.default 188 191 0.98:1
ChatWithPopoverPerf.default 375 387 0.97:1
ProviderMergeThemesPerf.default 1731 1791 0.97:1
ToolbarMinimalPerf.default 938 971 0.97:1
ButtonOverridesMissPerf.default 1746 1814 0.96:1
DropdownManyItemsPerf.default 673 700 0.96:1
LabelMinimalPerf.default 385 400 0.96:1
AccordionMinimalPerf.default 146 155 0.94:1
ReactionMinimalPerf.default 385 417 0.92:1

Comment on lines 147 to 151
/**
* The Avatar's image.
* Can either be the URL of the image, or the props of the img tag
*/
image?: string | ObjectShorthandProps<React.ImgHTMLAttributes<HTMLImageElement>>;
Copy link
Member

Choose a reason for hiding this comment

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

@behowell this is done to exclude other types from ShorthandProps are img does not have children, correct?

* Badge to show the avatar's presence status.
* Can either be a string indicating the status ("busy", "away", etc.), or a PresenceBadgeProps object.
*/
badge?: PresenceBadgeStatus | ObjectShorthandProps<PresenceBadgeProps>;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
badge?: PresenceBadgeStatus | ObjectShorthandProps<PresenceBadgeProps>;
badge?: PresenceBadgeStatus | ShorthandProps<PresenceBadgeProps>;

@behowell I can understand the case with image, but can you please clarify why we should not use ShorthandProps there? With ObjectShorthandProps it will be impossible to pass JSX elements:

<Avatar badge={<span />} />

Copy link
Member

Choose a reason for hiding this comment

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

the ComponentProps type actually exposes the props as ShorthandProps<ObjectShorthandProps>

@bsunderhus
Copy link
Contributor

Please, keep this blocked meanwhile the RFCs (#18949, #19068) are implemented 🙏🏼, otherwise we'll face a huge amount of conflicts. I'm hoping to finish the last RFC this week

@bsunderhus bsunderhus added the Status: Blocked Resolution blocked by another issue label Aug 23, 2021
@layershifter
Copy link
Member

@behowell as #19483 was merged, this is not blocked anymore. Can you please update this PR to include latest changes?

@layershifter layershifter removed the Status: Blocked Resolution blocked by another issue label Aug 31, 2021
@behowell behowell requested a review from a team as a code owner September 23, 2021 16:17
@behowell behowell requested a review from ling1726 as a code owner September 23, 2021 16:59
root: Omit<IntrinsicShorthandProps<'div'>, 'color'>;
icon?: IntrinsicShorthandProps<'span'>;
root: ObjectShorthandProps<React.HTMLAttributes<HTMLElement>>;
icon?: ObjectShorthandProps<React.HTMLAttributes<HTMLElement>>;
Copy link
Member

Choose a reason for hiding this comment

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

Do this mean that IntrinsicShorthandProps type does not work as it should?

Copy link
Member

Choose a reason for hiding this comment

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

yes, it's not working as it should, the unions completely break the Avatar when using PresenceBadgeProps

Copy link
Member

Choose a reason for hiding this comment

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

Can you please an issue for this problem?

Copy link
Member

@khmakoto khmakoto Sep 24, 2021

Choose a reason for hiding this comment

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

I had something like this happen with SplitButton yesterday. I can try and pull this branch and do what I did there to see if it works or just try to make the change later to not block this PR.

@ling1726 ling1726 enabled auto-merge (squash) September 24, 2021 11:06
Comment on lines -340 to -341
// 'colorful' should have been replaced with a color name by useAvatar, but if not default to darkRed
const color = state.color === 'colorful' ? 'darkRed' : state.color;
Copy link
Member

Choose a reason for hiding this comment

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

Did we just remove this logic?

Copy link
Member

Choose a reason for hiding this comment

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

I see now that this should be ensured in the useAvatar hook so there is no need for this anymore.

@ling1726 ling1726 merged commit afaf23b into microsoft:master Sep 24, 2021
bsunderhus added a commit to bsunderhus/fluentui that referenced this pull request Oct 1, 2021
bsunderhus added a commit that referenced this pull request Oct 4, 2021
* Fix Avatar stories after  #19449

* Change files
mlp73 pushed a commit to mlp73/fluentui that referenced this pull request Jan 17, 2022
* Initial work removing mergeProps from Avatar

* Refactor Avatar to remove mergeProps

* Update from latest changes to resolveShorthand

* Pull the slot names out into a separate array

* Remove null from badge and image types

* Move badge size and default icon to helper functions

* Fix up comments

* More refactoring

* More refactoring

* Change files

* Move logic to resolve 'colorful' back to useAvatar

* Fix badge size

* Remove unnecessary Partial

* Update for latest changes to root-as-slot and IntrinsicShorthandProps

* Change files

* Fix badge typings

* Change files

* fix tests

* change interfaces to types

* Change files

* update md

* revert react-utilities changes

* update md

* use undefined instaed of boolean for image

* fix ver tests

* make image typings scripts

Co-authored-by: Lingfan Gao <[email protected]>
mlp73 pushed a commit to mlp73/fluentui that referenced this pull request Jan 17, 2022
@behowell behowell deleted the avatar-unmergeprops branch July 25, 2022 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants