task: useAsync, cleanup ref after hook return is called#24093
task: useAsync, cleanup ref after hook return is called#24093micahgodbolt merged 2 commits intomicrosoft:masterfrom
Conversation
|
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 099deda:
|
Asset size changes
Baseline commit: ee025ccd3a919f2f4dcdd3a74dbe6d2abfed24ff (build) |
📊 Bundle size report🤖 This report was generated against ee025ccd3a919f2f4dcdd3a74dbe6d2abfed24ff |
Perf Analysis (
|
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| buttonNative | mount | 122 | 132 | 5000 | Possible regression |
All results
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| BaseButton | mount | 937 | 952 | 5000 | |
| Breadcrumb | mount | 2736 | 2776 | 1000 | |
| Checkbox | mount | 2618 | 2653 | 5000 | |
| CheckboxBase | mount | 2321 | 2305 | 5000 | |
| ChoiceGroup | mount | 4733 | 4732 | 5000 | |
| ComboBox | mount | 977 | 1035 | 1000 | |
| CommandBar | mount | 10583 | 10788 | 1000 | |
| ContextualMenu | mount | 11825 | 11783 | 1000 | |
| DefaultButton | mount | 1140 | 1160 | 5000 | |
| DetailsRow | mount | 3880 | 3940 | 5000 | |
| DetailsRowFast | mount | 3925 | 3858 | 5000 | |
| DetailsRowNoStyles | mount | 3744 | 3663 | 5000 | |
| Dialog | mount | 2855 | 2869 | 1000 | |
| DocumentCardTitle | mount | 183 | 179 | 1000 | |
| Dropdown | mount | 3390 | 3398 | 5000 | |
| FocusTrapZone | mount | 1905 | 1913 | 5000 | |
| FocusZone | mount | 1792 | 1816 | 5000 | |
| IconButton | mount | 1832 | 1774 | 5000 | |
| Label | mount | 356 | 348 | 5000 | |
| Layer | mount | 3177 | 3152 | 5000 | |
| Link | mount | 486 | 471 | 5000 | |
| MenuButton | mount | 1467 | 1509 | 5000 | |
| MessageBar | mount | 2176 | 2212 | 5000 | |
| Nav | mount | 3339 | 3394 | 1000 | |
| OverflowSet | mount | 1098 | 1115 | 5000 | |
| Panel | mount | 2264 | 2264 | 1000 | |
| Persona | mount | 1023 | 1010 | 1000 | |
| Pivot | mount | 1597 | 1479 | 1000 | |
| PrimaryButton | mount | 1328 | 1335 | 5000 | |
| Rating | mount | 7813 | 7889 | 5000 | |
| SearchBox | mount | 1328 | 1296 | 5000 | |
| Shimmer | mount | 2426 | 2541 | 5000 | |
| Slider | mount | 1949 | 2021 | 5000 | |
| SpinButton | mount | 5197 | 5067 | 5000 | |
| Spinner | mount | 448 | 447 | 5000 | |
| SplitButton | mount | 3241 | 3190 | 5000 | |
| Stack | mount | 515 | 534 | 5000 | |
| StackWithIntrinsicChildren | mount | 2314 | 2258 | 5000 | |
| StackWithTextChildren | mount | 5323 | 5237 | 5000 | |
| SwatchColorPicker | mount | 11746 | 11698 | 5000 | |
| TagPicker | mount | 2737 | 2804 | 5000 | |
| TeachingBubble | mount | 94380 | 94539 | 5000 | |
| Text | mount | 439 | 448 | 5000 | |
| TextField | mount | 1394 | 1425 | 5000 | |
| ThemeProvider | mount | 1236 | 1255 | 5000 | |
| ThemeProvider | virtual-rerender | 685 | 688 | 5000 | |
| ThemeProvider | virtual-rerender-with-unmount | 1837 | 1850 | 5000 | |
| Toggle | mount | 841 | 814 | 5000 | |
| buttonNative | mount | 122 | 132 | 5000 | Possible regression |
|
this is a good stopgap to resolve the react 18 issues, but we'll want to deprecate the existing async hook and move all of the fluent ui 8 and 9 controls to a unified set of hooks. Will open separate issues for that work. |
| const asyncRef = React.useRef<Async>(); | ||
| if (!asyncRef.current) { | ||
| asyncRef.current = new Async(); | ||
| } |
There was a problem hiding this comment.
FYI, just browsing the docs around upgrading to React 18, and it appears this pattern of assigning to the ref during render is explicitly considered an antipattern: reactwg/react-18#18 (comment)
fixes #24041
a new Async was not being create on each useAsync call, so in React 18 strict mode Async was created, then dispose was called, then useEffect fired again, but the Async remained disposed.