Skip to content

feat: add portal compat implementation to v8 & v0#22541

Merged
layershifter merged 8 commits into
microsoft:masterfrom
layershifter:feat/portal-compat-in-v0-n-v8
May 12, 2022
Merged

feat: add portal compat implementation to v8 & v0#22541
layershifter merged 8 commits into
microsoft:masterfrom
layershifter:feat/portal-compat-in-v0-n-v8

Conversation

@layershifter

@layershifter layershifter commented Apr 19, 2022

Copy link
Copy Markdown
Member

New Behavior

This PR adds implementation of portal compatibility to @fluentui/react & @fluentui/react-northstar based on RFC #21774.

Technically, these changes could go in separate PRs, but I wanted to make visible for reviewers changes in both libraries. The basic idea is to consume a callback from usePortalCompat() and call it when an element that is used in ReactDOM.createPortal() is created.

The compat implemented can be found in #22510, this PR adds @fluentui/react-portal-compat-context to dependencies of both packages.

const registerPortalEl = usePortalCompat();
const element = createPortalElement();

useIsomorphicLayoutEffect(() => {
  return element(box);
}, [element, registerPortalEl]);

👀 Check demo to see how it works.

Related Issue(s)

Follows #22466, #22510.

@codesandbox-ci

codesandbox-ci Bot commented May 2, 2022

Copy link
Copy Markdown

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 2a55e6c:

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

@fabricteam

fabricteam commented May 2, 2022

Copy link
Copy Markdown
Collaborator

📊 Bundle size report

🤖 This report was generated against 5ab96eaa4a341c54b1e6e609f4e518c57cd1320b

@size-auditor

size-auditor Bot commented May 2, 2022

Copy link
Copy Markdown

Asset size changes

Project Bundle Baseline Size New Size Difference
office-ui-fabric-react fluentui-react-northstar-SplitButton 193.399 kB 193.663 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Dialog 124.83 kB 125.094 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Chat 166.459 kB 166.723 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Portal 59.163 kB 59.427 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Popup 146.948 kB 147.212 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Dropdown 212.456 kB 212.72 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-MenuButton 177.131 kB 177.395 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Datepicker 202.122 kB 202.386 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Tooltip 120.766 kB 121.03 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-northstar-Toolbar 189.647 kB 189.911 kB ExceedsBaseline     264 bytes
office-ui-fabric-react fluentui-react-Panel 187.309 kB 187.441 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Persona 108.483 kB 108.615 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-DetailsList 217.459 kB 217.591 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-PersonaCoin 108.483 kB 108.615 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Pickers 273.548 kB 273.68 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Pivot 176.192 kB 176.324 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-DocumentCard 202.679 kB 202.811 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-MessageBar 175.95 kB 176.082 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Nav 175.262 kB 175.394 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Modal 89.437 kB 89.569 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-PositioningContainer 69.143 kB 69.275 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Dropdown 218.717 kB 218.849 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Facepile 197.378 kB 197.51 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Keytips 100.08 kB 100.212 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-KeytipLayer 97.36 kB 97.492 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Keytip 76.198 kB 76.33 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-FloatingPicker 227.321 kB 227.453 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-HoverCard 92.079 kB 92.211 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Dialog 196.812 kB 196.944 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Grid 168.12 kB 168.252 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Callout 79.483 kB 79.615 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-ShimmeredDetailsList 228.086 kB 228.218 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-TeachingBubble 192.009 kB 192.141 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-SwatchColorPicker 177.812 kB 177.944 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-TimePicker 223.541 kB 223.673 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-ButtonGrid 168.12 kB 168.252 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-DatePicker 174.382 kB 174.514 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Tooltip 81.086 kB 81.218 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Coachmark 88.115 kB 88.247 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-SpinButton 178.785 kB 178.917 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Button 182.153 kB 182.285 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Breadcrumb 187.351 kB 187.483 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-ColorPicker 124.483 kB 124.615 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-SelectedItemsList 217.085 kB 217.217 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-ComboBox 234.09 kB 234.222 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-SearchBox 174.908 kB 175.04 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-CommandBar 188.301 kB 188.433 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-ContextualMenu 143.49 kB 143.622 kB ExceedsBaseline     132 bytes
office-ui-fabric-react fluentui-react-Layer 45.558 kB 45.689 kB ExceedsBaseline     131 bytes

ExceedsTolerance Over Tolerance (1024 B) ExceedsBaseline Over Baseline BelowBaseline Below Baseline New New Deleted  Removed 1 kB = 1000 B

Baseline commit: 5ab96eaa4a341c54b1e6e609f4e518c57cd1320b (build)

@layershifter layershifter force-pushed the feat/portal-compat-in-v0-n-v8 branch from 5cb911e to 6fd48c5 Compare May 2, 2022 09:52
@layershifter layershifter force-pushed the feat/portal-compat-in-v0-n-v8 branch from 6fd48c5 to 5b7a811 Compare May 2, 2022 09:56
@fabricteam

fabricteam commented May 2, 2022

Copy link
Copy Markdown
Collaborator

Perf Analysis (@fluentui/react-northstar)

Perf tests with no regressions
Scenario Current PR Ticks Baseline Ticks Ratio
AttachmentMinimalPerf.default 168 141 1.19:1
FormMinimalPerf.default 425 391 1.09:1
RefMinimalPerf.default 250 234 1.07:1
AvatarMinimalPerf.default 201 189 1.06:1
CheckboxMinimalPerf.default 2814 2663 1.06:1
ProviderMinimalPerf.default 405 381 1.06:1
GridMinimalPerf.default 345 329 1.05:1
HeaderMinimalPerf.default 373 354 1.05:1
HeaderSlotsPerf.default 790 751 1.05:1
TextAreaMinimalPerf.default 486 462 1.05:1
ButtonMinimalPerf.default 160 154 1.04:1
SkeletonMinimalPerf.default 340 327 1.04:1
StatusMinimalPerf.default 677 654 1.04:1
AnimationMinimalPerf.default 543 525 1.03:1
ButtonOverridesMissPerf.default 1533 1492 1.03:1
ImageMinimalPerf.default 365 355 1.03:1
ItemLayoutMinimalPerf.default 1187 1155 1.03:1
LabelMinimalPerf.default 384 372 1.03:1
MenuButtonMinimalPerf.default 1773 1722 1.03:1
DialogMinimalPerf.default 772 760 1.02:1
DropdownMinimalPerf.default 3069 3018 1.02:1
EmbedMinimalPerf.default 4201 4135 1.02:1
InputMinimalPerf.default 1301 1273 1.02:1
ListMinimalPerf.default 505 497 1.02:1
ListNestedPerf.default 542 529 1.02:1
ListWith60ListItems.default 653 643 1.02:1
SegmentMinimalPerf.default 343 335 1.02:1
TableManyItemsPerf.default 1955 1917 1.02:1
ToolbarMinimalPerf.default 968 948 1.02:1
TreeMinimalPerf.default 836 818 1.02:1
CardMinimalPerf.default 572 564 1.01:1
ChatDuplicateMessagesPerf.default 295 292 1.01:1
ChatMinimalPerf.default 753 742 1.01:1
FlexMinimalPerf.default 286 284 1.01:1
PopupMinimalPerf.default 634 630 1.01:1
SplitButtonMinimalPerf.default 4409 4381 1.01:1
TableMinimalPerf.default 388 386 1.01:1
TextMinimalPerf.default 335 331 1.01:1
CustomToolbarPrototype.default 2756 2723 1.01:1
TooltipMinimalPerf.default 1111 1102 1.01:1
LoaderMinimalPerf.default 689 691 1:1
ProviderMergeThemesPerf.default 1263 1269 1:1
RadioGroupMinimalPerf.default 449 451 1:1
SliderMinimalPerf.default 1687 1688 1:1
VideoMinimalPerf.default 659 658 1:1
AttachmentSlotsPerf.default 1057 1073 0.99:1
CarouselMinimalPerf.default 482 489 0.99:1
MenuMinimalPerf.default 861 869 0.99:1
ReactionMinimalPerf.default 381 384 0.99:1
ChatWithPopoverPerf.default 378 386 0.98:1
DividerMinimalPerf.default 346 353 0.98:1
DropdownManyItemsPerf.default 665 677 0.98:1
ListCommonPerf.default 648 658 0.98:1
PortalMinimalPerf.default 168 172 0.98:1
IconMinimalPerf.default 590 605 0.98:1
DatepickerMinimalPerf.default 5816 5969 0.97:1
BoxMinimalPerf.default 327 340 0.96:1
ButtonSlotsPerf.default 536 561 0.96:1
LayoutMinimalPerf.default 342 360 0.95:1
RosterPerf.default 1090 1148 0.95:1
AccordionMinimalPerf.default 138 147 0.94:1
AlertMinimalPerf.default 271 287 0.94:1
TreeWith60ListItems.default 173 185 0.94:1

@fabricteam

fabricteam commented May 2, 2022

Copy link
Copy Markdown
Collaborator

Perf Analysis (@fluentui/react)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
BaseButton mount 932 925 5000
Breadcrumb mount 2824 2805 1000
Checkbox mount 1628 1542 5000
CheckboxBase mount 1353 1496 5000
ChoiceGroup mount 4910 4982 5000
ComboBox mount 1041 1081 1000
CommandBar mount 10875 11083 1000
ContextualMenu mount 12261 12302 1000
DefaultButton mount 1175 1172 5000
DetailsRow mount 4074 4115 5000
DetailsRowFast mount 4320 4077 5000
DetailsRowNoStyles mount 3819 3804 5000
Dialog mount 2461 2466 1000
DocumentCardTitle mount 197 202 1000
Dropdown mount 3605 3658 5000
FocusTrapZone mount 1928 2062 5000
FocusZone mount 1984 1868 5000
IconButton mount 1766 1970 5000
Label mount 391 416 5000
Layer mount 3159 3167 5000
Link mount 527 515 5000
MenuButton mount 1578 1509 5000
MessageBar mount 2289 2372 5000
Nav mount 3507 3455 1000
OverflowSet mount 1107 1134 5000
Panel mount 2327 2241 1000
Persona mount 1058 1033 1000
Pivot mount 1479 1449 1000
PrimaryButton mount 1330 1309 5000
Rating mount 7971 7858 5000
SearchBox mount 1408 1273 5000
Shimmer mount 2724 2532 5000
Slider mount 1965 2035 5000
SpinButton mount 5580 5287 5000
Spinner mount 486 488 5000
SplitButton mount 3298 3231 5000
Stack mount 526 522 5000
StackWithIntrinsicChildren mount 2669 2499 5000
StackWithTextChildren mount 5749 5548 5000
SwatchColorPicker mount 11863 11913 5000
TagPicker mount 2837 2905 5000
TeachingBubble mount 97750 97272 5000
Text mount 424 417 5000
TextField mount 1407 1469 5000
ThemeProvider mount 1265 1199 5000
ThemeProvider virtual-rerender 720 666 5000
ThemeProvider virtual-rerender-with-unmount 1976 2040 5000
Toggle mount 832 837 5000
buttonNative mount 149 143 5000

logger('STEP 2. Add Fluent UI dependency to test project..');

const packedPackages = await packProjectPackages(logger, config.paths.packages(), ['@fluentui/react-northstar']);
const packedPackages = await packProjectPackages(logger, config.paths.base(), ['@fluentui/react-northstar']);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As we have a package outside packages/fluentui I had to change the root to include @fluentui/react-portal-compat-context into the list of packages to build.

"@fluentui/react-component-ref": "^0.62.0",
"@fluentui/react-icons-northstar": "^0.62.0",
"@fluentui/react-northstar-styles-renderer": "^0.62.0",
"@fluentui/react-portal-compat-context": "^9.0.0-rc.0",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For v9 we don't use carets, but as it goes to production versions of libraries I think that it's better to actually use them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It makes sense, but there is a risk of API breakage before release

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To clarify, this is only for @fluentui/react-portal-compat-context. If there will be a breaking change I will major bump the package instead, but it's unlikely will ever happen.

Comment on lines +28 to +31
const classes = className.split(' ').filter(Boolean);

if (element) {
element.setAttribute('class', className);
element.classList.add(...classes);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Had to rework this section because otherwise .setAttribute() overwrites all classes and caused glitches during theme switches.

@layershifter layershifter marked this pull request as ready for review May 2, 2022 13:33
@layershifter layershifter requested review from a team and ThomasMichon as code owners May 2, 2022 13:33
@layershifter layershifter requested a review from Hotell May 2, 2022 13:34
Comment on lines +40 to +45
return () => {
if (element) {
element.classList.remove(...classes);
element.removeAttribute('dir');
}
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Previous behaviour didn't do this, are you just adding this now for correctness ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Adding now to be more consistent.

@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore "react-portal-compat-context" uses v9 configs via path aliases

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wondering if we need this ? react-portal-compat-context is a dependency of this package so to be able to get proper types etc one needs to run lage build --to which will trigger build also for this v9 package, thus I assume this can be removed ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, you're totally correct 🐱 I made a change for N*, but then totally forgot about "build-me-first" behavior in @fluentui/react...

@layershifter

Copy link
Copy Markdown
Member Author

@microsoft/cxe-red can someone please check this PR?

@layershifter layershifter merged commit 0915fee into microsoft:master May 12, 2022
@layershifter layershifter deleted the feat/portal-compat-in-v0-n-v8 branch May 12, 2022 09:54
marwan38 pushed a commit to marwan38/fluentui that referenced this pull request Jun 13, 2022
* feat: add portal compat implementation to v8 & v0

* fix config

* fix project test

* remove useless tsignore

* fix dependency versions

* add changelog entry

* fix path
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.

6 participants