Skip to content

task: useAsync, cleanup ref after hook return is called#24093

Merged
micahgodbolt merged 2 commits intomicrosoft:masterfrom
micahgodbolt:useasync-cleanup
Jul 27, 2022
Merged

task: useAsync, cleanup ref after hook return is called#24093
micahgodbolt merged 2 commits intomicrosoft:masterfrom
micahgodbolt:useasync-cleanup

Conversation

@micahgodbolt
Copy link
Member

@micahgodbolt micahgodbolt commented Jul 26, 2022

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.

@codesandbox-ci
Copy link

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:

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

@size-auditor
Copy link

size-auditor bot commented Jul 26, 2022

Asset size changes

Project Bundle Baseline Size New Size Difference
office-ui-fabric-react fluentui-react-Pivot 177.673 kB 177.74 kB ExceedsBaseline     67 bytes
office-ui-fabric-react fluentui-react-TimePicker 225.204 kB 225.271 kB ExceedsBaseline     67 bytes
office-ui-fabric-react fluentui-react-DocumentCard 204.147 kB 204.213 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Pickers 275.608 kB 275.674 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Panel 187.849 kB 187.915 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Nav 176.872 kB 176.938 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Keytips 100.91 kB 100.976 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-HoverCard 92.073 kB 92.139 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Grid 169.562 kB 169.628 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-FloatingPicker 229.092 kB 229.158 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Facepile 198.846 kB 198.912 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Dropdown 219.743 kB 219.809 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Breadcrumb 188.829 kB 188.895 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-SearchBox 176.376 kB 176.442 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-DatePicker 174.839 kB 174.905 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-ContextualMenu 144.916 kB 144.982 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-CommandBar 189.867 kB 189.933 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-ComboBox 236.058 kB 236.124 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Coachmark 88.113 kB 88.179 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Callout 79.474 kB 79.54 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-ButtonGrid 169.562 kB 169.628 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Button 183.624 kB 183.69 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Dialog 198.017 kB 198.083 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-MessageBar 177.418 kB 177.484 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-SpinButton 180.275 kB 180.341 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-SelectedItemsList 218.822 kB 218.888 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-TeachingBubble 192.555 kB 192.621 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-SwatchColorPicker 179.254 kB 179.32 kB ExceedsBaseline     66 bytes
office-ui-fabric-react fluentui-react-Persona 109.341 kB 109.39 kB ExceedsBaseline     49 bytes
office-ui-fabric-react fluentui-react-Tooltip 81.927 kB 81.976 kB ExceedsBaseline     49 bytes
office-ui-fabric-react fluentui-react-KeytipLayer 98.191 kB 98.24 kB ExceedsBaseline     49 bytes
office-ui-fabric-react fluentui-react-ColorPicker 125.324 kB 125.373 kB ExceedsBaseline     49 bytes
office-ui-fabric-react fluentui-react-PersonaCoin 109.341 kB 109.39 kB ExceedsBaseline     49 bytes
office-ui-fabric-react fluentui-react-ResizeGroup 13.229 kB 13.275 kB ExceedsBaseline     46 bytes
office-ui-fabric-react fluentui-react-Modal 90.15 kB 90.195 kB ExceedsBaseline     45 bytes
office-ui-fabric-react fluentui-react-Keytip 77.028 kB 77.073 kB ExceedsBaseline     45 bytes
office-ui-fabric-react fluentui-react-PositioningContainer 69.978 kB 69.946 kB BelowBaseline     -32 bytes
office-ui-fabric-react fluentui-react-Popup 12.074 kB 12.021 kB BelowBaseline     -53 bytes

ExceedsTolerance Over Tolerance (1024 B) ExceedsBaseline Over Baseline BelowBaseline Below Baseline New New Deleted  Removed 1 kB = 1000 B

Baseline commit: ee025ccd3a919f2f4dcdd3a74dbe6d2abfed24ff (build)

@fabricteam
Copy link
Collaborator

📊 Bundle size report

🤖 This report was generated against ee025ccd3a919f2f4dcdd3a74dbe6d2abfed24ff

@fabricteam
Copy link
Collaborator

Perf Analysis (@fluentui/react)

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

@micahgodbolt
Copy link
Member Author

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.

@micahgodbolt micahgodbolt merged commit d02dcc1 into microsoft:master Jul 27, 2022
@micahgodbolt micahgodbolt deleted the useasync-cleanup branch July 27, 2022 23:48
Comment on lines +8 to +11
const asyncRef = React.useRef<Async>();
if (!asyncRef.current) {
asyncRef.current = new Async();
}
Copy link

Choose a reason for hiding this comment

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

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)

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.

V8 Callouts do not render in React 18 Strict Mode

7 participants