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: Update position when target or container dimensions change #30179

Merged

Conversation

ling1726
Copy link
Member

@ling1726 ling1726 commented Dec 29, 2023

Uses a ResizeObserver in the position manager so that a position update is triggered when the dimension of the target or container changes. This should handle most async update scenarios without needing to call updatePosition in userland.

The ResizeObserver will only be created when:

  • both target and positioned element that refer to HTML elements
  • the positionig logic is enabled

Practically this means that the ResizeObserver is created only when Popover/Menu/Combobox/Tooltip etc... are open. Just mounting an (unopened) Popover will not create a new ResizeObserver

Fixes #29998

Uses a ResizeObserver in the position manager so that a position update
is triggered when the dimension of the target or container changes. This
should handle most async update scenarios without needing to call
`updatePosition` in userland.

Fixes #
@fabricteam
Copy link
Collaborator

fabricteam commented Dec 29, 2023

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 606 627 5000
Button mount 305 294 5000
Field mount 1155 1148 5000
FluentProvider mount 716 705 5000
FluentProviderWithTheme mount 84 79 10
FluentProviderWithTheme virtual-rerender 77 69 10
FluentProviderWithTheme virtual-rerender-with-unmount 86 87 10
MakeStyles mount 846 870 50000
Persona mount 1753 1731 5000
SpinButton mount 1411 1381 5000

Copy link

codesandbox-ci bot commented Dec 29, 2023

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 489bdc7:

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

@fabricteam
Copy link
Collaborator

fabricteam commented Dec 29, 2023

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-combobox
Combobox (including child components)
95.057 kB
30.655 kB
95.176 kB
30.712 kB
119 B
57 B
react-combobox
Dropdown (including child components)
93.643 kB
30.333 kB
93.762 kB
30.392 kB
119 B
59 B
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
209.783 kB
59.86 kB
209.902 kB
59.921 kB
119 B
61 B
react-datepicker-compat
DatePicker Compat
213.537 kB
59.885 kB
213.655 kB
59.945 kB
118 B
60 B
react-infobutton
InfoButton
132.618 kB
41.704 kB
132.737 kB
41.771 kB
119 B
67 B
react-infobutton
InfoLabel
136.305 kB
42.845 kB
136.424 kB
42.903 kB
119 B
58 B
react-menu
Menu (including children components)
141.968 kB
43.516 kB
142.087 kB
43.579 kB
119 B
63 B
react-menu
Menu (including selectable components)
144.654 kB
44.025 kB
144.773 kB
44.088 kB
119 B
63 B
react-popover
Popover
120.812 kB
38.11 kB
120.931 kB
38.165 kB
119 B
55 B
react-positioning
usePositioning
25.767 kB
9.308 kB
25.891 kB
9.362 kB
124 B
54 B
react-timepicker-compat
TimePicker
96.894 kB
32.105 kB
97.013 kB
32.163 kB
119 B
58 B
react-timepicker-compat-preview
TimePicker
96.894 kB
32.105 kB
97.013 kB
32.163 kB
119 B
58 B
react-tooltip
Tooltip
53.252 kB
18.806 kB
53.371 kB
18.855 kB
119 B
49 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-alert
Alert
83.737 kB
23.474 kB
react-avatar
Avatar
50.175 kB
15.944 kB
react-avatar
AvatarGroup
19.704 kB
7.796 kB
react-avatar
AvatarGroupItem
64.831 kB
20.274 kB
react-components
react-components: Button, FluentProvider & webLightTheme
69.901 kB
20.261 kB
react-components
react-components: FluentProvider & webLightTheme
42.388 kB
14.103 kB
react-persona
Persona
57.066 kB
17.821 kB
react-portal-compat
PortalCompatProvider
7.099 kB
2.385 kB
react-table
DataGrid
154.896 kB
43.531 kB
react-table
Table (Primitives only)
43.899 kB
13.781 kB
react-table
Table as DataGrid
128.117 kB
34.788 kB
react-table
Table (Selection only)
73.296 kB
20.012 kB
react-table
Table (Sort only)
71.903 kB
19.613 kB
react-tags
InteractionTag
15.259 kB
6.058 kB
react-tags
Tag
29.982 kB
9.439 kB
react-tags
TagGroup
74.331 kB
22.28 kB
🤖 This report was generated against a493617d5c710d78246d315e67fa7eb2d7b6b9f9

Copy link

size-auditor bot commented Dec 29, 2023

Asset size changes

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

Baseline commit: a493617d5c710d78246d315e67fa7eb2d7b6b9f9 (build)

@ling1726 ling1726 requested a review from a team as a code owner December 29, 2023 18:53
Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

Code in this PR LGTM ✅

The idea to have a resize observer for every popup & tooltip looked initially scary, however that statement is not correct: we will have observers only for opened popups (usually 1 or 2) & visible tooltips (should be one on a page).

P.S. Please also consider adding an option to disable this behavior.

@ling1726 ling1726 merged commit 0893aaa into microsoft:master Jan 8, 2024
24 checks passed
Leolewin pushed a commit to Leolewin/fluentui that referenced this pull request Jan 9, 2024
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Jan 10, 2024
* master: (166 commits)
  Remove v0 dependency from v0 compat package (microsoft#30276)
  applying package updates
  Disallow `window` and `document` access for `@fluentui/react` and related packages. (microsoft#30063)
  Update Rating api and stories (microsoft#30092)
  TeachingPopover: Minor style changes (microsoft#30270)
  feat(scripts-gulp): replace lerna with nx (microsoft#30266)
  ci: remove canary and nightly functionality from northstar (microsoft#30264)
  List: Re-initialize on mount in React 18. (microsoft#29881)
  feat(scripts-monorepo): replace lerna/utils with pure nx apis (microsoft#30178)
  chore: remove react-timepicker-compat-preview (microsoft#30263)
  applying package updates
  feat(TimePicker-compat): stable release  (microsoft#30217)
  feat: Implement onPositioningEnd callback (microsoft#30177)
  applying package updates
  v8 registerIcons compat (microsoft#30003)
  Adding Planner, ToDoItem and updated Project filetype icons. Updating FabricCDN url to latest datecode. (microsoft#30079)
  Scaffolds more Nav components (microsoft#30227)
  chore: migrate to nx 17.2 (microsoft#30187)
  applying package updates
  feat: Update position when target or container dimensions change (microsoft#30179)
  ...
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.

Positioned elements should reposition on resize
3 participants