feat: positioning should happen out of React lifecycle#25456
Merged
ling1726 merged 18 commits intomicrosoft:masterfrom Nov 2, 2022
Merged
feat: positioning should happen out of React lifecycle#25456ling1726 merged 18 commits intomicrosoft:masterfrom
ling1726 merged 18 commits intomicrosoft:masterfrom
Conversation
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
Collaborator
📊 Bundle size reportUnchanged fixtures
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: bfc4a96dc4e1f1b656f8c9f0edd06b1005fc2284 (build) |
Collaborator
Perf Analysis (
|
| 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 |
|
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:
|
usePositioning
ling1726
commented
Nov 1, 2022
packages/react-components/react-positioning/src/utils/writeContainerupdates.ts
Outdated
Show resolved
Hide resolved
ling1726
commented
Nov 1, 2022
change/@fluentui-react-positioning-b6d61cdf-e434-43ff-a859-ab563e6a47f5.json
Outdated
Show resolved
Hide resolved
layershifter
reviewed
Nov 1, 2022
packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts
Show resolved
Hide resolved
packages/react-components/react-positioning/etc/react-positioning.api.md
Outdated
Show resolved
Hide resolved
packages/react-components/react-positioning/src/utils/writeContainerupdates.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-positioning/src/createPositionManager.ts
Show resolved
Hide resolved
packages/react-components/react-positioning/src/createPositionManager.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-positioning/src/createPositionManager.ts
Outdated
Show resolved
Hide resolved
Comment on lines
+37
to
39
| if (managerRef.current) { | ||
| managerRef.current.dispose(); | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| if (managerRef.current) { | |
| managerRef.current.dispose(); | |
| } | |
| managerRef.current?.dispose(); |
nit
packages/react-components/react-positioning/src/usePositioning.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-positioning/src/usePositioning.ts
Outdated
Show resolved
Hide resolved
…ling1726/fluentui into feat/use-positioning-ref-update
layershifter
approved these changes
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


usePositioning
Positioning is now handled by a new
PositioningManagerthat 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
usePortalMountNodeto create all the attributes of the mount node during the render phase inuseMemoto 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 changesFixes #25432
Fixes #25326