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

feat: positioning should happen out of React lifecycle #25456

Merged
merged 18 commits into from
Nov 2, 2022

Conversation

ling1726
Copy link
Member

@ling1726 ling1726 commented Nov 1, 2022

usePositioning

Positioning is now handled by a new PositioningManager that is a non-react instance. This means that position updates and event listeners can be done without needing to follow react lifecycle.

callback refs are still returned by usePositioning, but internally these callback refs refs are only used to set real refs. This makes the flow of the logic a lot clearer previously the usages of the callback refs could occur before they are even declared.

usePortalMountNode

Also updates usePortalMountNode to create all the attributes of the mount node during the render phase in useMemo to avoid any css variable changes during render time which can cause strange styling bugs due to changes in CSS variables. Since our portals are already broken in react 18 strict mode, we're not making that worse with these changes

Fixes #25432
Fixes #25326

Updates the ref handling done in `usePositioning` so that scroll
listeners are only added when both container, target elements are set
correctly and the behaviour is `enabled`. This ensures that the browser
reflow caused by `getScrollParent` is called as little as possible.

Also updates `usePortalMountNode` to create all the attributes of the
mount node during the render phase in `useMemo` to avoid any css
variable changes during render time which can cause strange styling bugs
due to changes in CSS variables. Since our portals are already broken in
react 18 strict mode, we're not making that worse with these changes
@fabricteam
Copy link
Collaborator

fabricteam commented Nov 1, 2022

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-combobox
Combobox (including child components)
75.85 kB
24.632 kB
76.153 kB
24.665 kB
303 B
33 B
react-combobox
Dropdown (including child components)
75.579 kB
24.594 kB
75.885 kB
24.635 kB
306 B
41 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
189.603 kB
52.909 kB
189.906 kB
52.963 kB
303 B
54 B
react-menu
Menu (including children components)
116.78 kB
36.112 kB
117.089 kB
36.188 kB
309 B
76 B
react-menu
Menu (including selectable components)
119.849 kB
36.635 kB
120.158 kB
36.712 kB
309 B
77 B
react-popover
Popover
103.342 kB
31.82 kB
103.672 kB
31.871 kB
330 B
51 B
react-portal
Portal
10.628 kB
3.899 kB
10.495 kB
3.851 kB
-133 B
-48 B
react-positioning
usePositioning
19.724 kB
7.415 kB
19.826 kB
7.417 kB
102 B
2 B
react-tooltip
Tooltip
41.718 kB
14.687 kB
42.032 kB
14.739 kB
314 B
52 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-alert
Alert
84.688 kB
21.233 kB
react-avatar
Avatar
48.874 kB
13.864 kB
react-avatar
AvatarGroup
14.996 kB
6.013 kB
react-avatar
AvatarGroupItem
63.452 kB
17.959 kB
react-components
react-components: Button, FluentProvider & webLightTheme
62.94 kB
17.663 kB
react-components
react-components: FluentProvider & webLightTheme
33.446 kB
11.033 kB
react-dialog
Dialog (including children components)
83.147 kB
24.799 kB
react-persona
Persona
53.992 kB
15.25 kB
react-portal-compat
PortalCompatProvider
5.857 kB
1.978 kB
🤖 This report was generated against bfc4a96dc4e1f1b656f8c9f0edd06b1005fc2284

@size-auditor
Copy link

size-auditor bot commented Nov 1, 2022

Asset size changes

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

Baseline commit: bfc4a96dc4e1f1b656f8c9f0edd06b1005fc2284 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Nov 1, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1315 1309 5000
Button mount 902 949 5000
FluentProvider mount 1594 1563 5000
FluentProviderWithTheme mount 633 632 10
FluentProviderWithTheme virtual-rerender 525 597 10
FluentProviderWithTheme virtual-rerender-with-unmount 634 560 10
MakeStyles mount 1775 1859 50000
SpinButton mount 2337 2527 5000

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 1, 2022

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 96ad42a:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration
Tooltip and computed style Issue #25326
inspiring-chihiro-w571tp Issue #25432

@ling1726 ling1726 changed the title feat: Updates ref update handling in usePositioning feat: positioning should happen out of React lifecycle Nov 1, 2022
@ling1726 ling1726 marked this pull request as ready for review November 1, 2022 12:26
@ling1726 ling1726 requested a review from a team as a code owner November 1, 2022 12:26
Comment on lines +37 to 39
if (managerRef.current) {
managerRef.current.dispose();
}
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
if (managerRef.current) {
managerRef.current.dispose();
}
managerRef.current?.dispose();

nit

@ling1726 ling1726 requested a review from layershifter November 2, 2022 11:17
@ling1726 ling1726 merged commit 393a7b1 into microsoft:master Nov 2, 2022
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Nov 2, 2022
* master: (23 commits)
  fix(docsite-v9): move theme picker under component title so it can be visible on embedded pages (microsoft#25385)
  applying package updates
  feat: Implement child render function for DataGrid rows (microsoft#25476)
  fix(useTable): sort should adapt to enhanced row types (microsoft#25487)
  applying package updates
  feat: positioning should happen out of React lifecycle (microsoft#25456)
  applying package updates
  chore(react-link): migrate to new package structure (microsoft#25471)
  chore(react-input): migrate to new package structure (microsoft#25469)
  fix glob pattern for syncpack (microsoft#25465)
  chore(react-label): migrate to new package structure (microsoft#25470)
  chore: bump Griffel to latest (microsoft#25412)
  chore: add few small toolbar improvements (microsoft#25468)
  docs: fix small typos (microsoft#25464)
  chore: fix dependencies in @fluentui/react-toolbar (microsoft#25466)
  feat: v0 menu style migration from v9 (microsoft#25012)
  applying package updates
  Update List to render children on first render() call (microsoft#25331)
  Scaffold react-skeleton package (microsoft#25435)
  fix(public-docsite): Changing crossplatform urls to use 'cross' instead of 'crossplatform' (microsoft#25437)
  ...
NotWoods pushed a commit to NotWoods/fluentui that referenced this pull request Nov 18, 2022
* feat: Updates ref update handling in `usePositioning`

Updates the ref handling done in `usePositioning` so that scroll
listeners are only added when both container, target elements are set
correctly and the behaviour is `enabled`. This ensures that the browser
reflow caused by `getScrollParent` is called as little as possible.

Also updates `usePortalMountNode` to create all the attributes of the
mount node during the render phase in `useMemo` to avoid any css
variable changes during render time which can cause strange styling bugs
due to changes in CSS variables. Since our portals are already broken in
react 18 strict mode, we're not making that worse with these changes

* revert button changes

* changefiles

* update md

* fix ssr

* update

* fix blurriness

* Update change/@fluentui-react-positioning-b6d61cdf-e434-43ff-a859-ab563e6a47f5.json

* document usePortalMountNode memo

* fix breaking api

* rename to targetWindow

* createPositionManager is internal

* short circuit

* update check to include override target

* remove useless improt

* revert blurriness change

* fix position fixed and effect
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* feat: Updates ref update handling in `usePositioning`

Updates the ref handling done in `usePositioning` so that scroll
listeners are only added when both container, target elements are set
correctly and the behaviour is `enabled`. This ensures that the browser
reflow caused by `getScrollParent` is called as little as possible.

Also updates `usePortalMountNode` to create all the attributes of the
mount node during the render phase in `useMemo` to avoid any css
variable changes during render time which can cause strange styling bugs
due to changes in CSS variables. Since our portals are already broken in
react 18 strict mode, we're not making that worse with these changes

* revert button changes

* changefiles

* update md

* fix ssr

* update

* fix blurriness

* Update change/@fluentui-react-positioning-b6d61cdf-e434-43ff-a859-ab563e6a47f5.json

* document usePortalMountNode memo

* fix breaking api

* rename to targetWindow

* createPositionManager is internal

* short circuit

* update check to include override target

* remove useless improt

* revert blurriness change

* fix position fixed and effect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants