-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat: positioning should happen out of React lifecycle #25456
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
📊 Bundle size reportUnchanged fixtures
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: bfc4a96dc4e1f1b656f8c9f0edd06b1005fc2284 (build) |
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
packages/react-components/react-positioning/src/utils/writeContainerupdates.ts
Outdated
Show resolved
Hide resolved
change/@fluentui-react-positioning-b6d61cdf-e434-43ff-a859-ab563e6a47f5.json
Outdated
Show resolved
Hide resolved
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
if (managerRef.current) { | ||
managerRef.current.dispose(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
* 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) ...
* 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
* 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
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 inuseMemo
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 changesFixes #25432
Fixes #25326