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(useTable): selection manager to avoid calling multiple hooks #24377

Merged
merged 6 commits into from
Aug 17, 2022

Conversation

ling1726
Copy link
Member

@ling1726 ling1726 commented Aug 16, 2022

Implements a createSelectionManager constructor to manage selection state
independently of react and avoids calling state hooks twice on each
render

Addresses #24226

Implements a `createSelectionManager` function to manage selection state
independently of react and avoids calling state hooks twice on each
render
@ling1726 ling1726 marked this pull request as ready for review August 16, 2022 10:56
@ling1726 ling1726 requested a review from a team as a code owner August 16, 2022 10:56
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 16, 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 463d1b9:

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

@fabricteam
Copy link
Collaborator

fabricteam commented Aug 16, 2022

📊 Bundle size report

Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
189.042 kB
51.964 kB
react-components
react-components: FluentProvider & webLightTheme
32.895 kB
10.778 kB
🤖 This report was generated against 06dfea83bd8c002e8219b97ab0f3deecc1365e37

@size-auditor
Copy link

size-auditor bot commented Aug 16, 2022

Asset size changes

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

Baseline commit: 06dfea83bd8c002e8219b97ab0f3deecc1365e37 (build)

@fabricteam
Copy link
Collaborator

fabricteam commented Aug 16, 2022

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1488 1493 5000
Button mount 1124 1130 5000
FluentProvider mount 1861 1852 5000
FluentProviderWithTheme mount 751 745 10
FluentProviderWithTheme virtual-rerender 688 697 10
FluentProviderWithTheme virtual-rerender-with-unmount 741 738 10
MakeStyles mount 2277 2249 50000
SpinButton mount 2923 2991 5000

Comment on lines +13 to +21
const [selectionManager, setSelectionManager] = React.useState(() =>
createSelectionManager(selectionMode, setSelected),
);

return selectionMode === 'multiselect' ? multipleSelectionState : singleSelectionState;
React.useEffect(() => {
if (prevSelectionMode !== selectionMode) {
setSelectionManager(createSelectionManager(selectionMode, setSelected));
}
}, [selectionMode, prevSelectionMode]);
Copy link
Member

Choose a reason for hiding this comment

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

not blocking: Let's pair on creating useSingletone or something like that as people who are not aware about Strict mode issues will be confused.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah we even have a task for it, but not sure how much of a priority 18 is yet #24085

Copy link
Contributor

@bsunderhus bsunderhus left a comment

Choose a reason for hiding this comment

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

LGTM

@ling1726 ling1726 merged commit 02a6a76 into microsoft:master Aug 17, 2022
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.

4 participants