Skip to content

Fix onResolveSuggestions not being called after component is remounted in react 18 strict mode#28227

Merged
khmakoto merged 2 commits intomicrosoft:masterfrom
andyrooger:25441-onresolvesuggestions-not-triggered
Sep 9, 2024
Merged

Fix onResolveSuggestions not being called after component is remounted in react 18 strict mode#28227
khmakoto merged 2 commits intomicrosoft:masterfrom
andyrooger:25441-onresolvesuggestions-not-triggered

Conversation

@andyrooger
Copy link
Contributor

Previous Behavior

When running in react 18 strict mode, the suggestion list does not display in pickers.

In strict mode, rather than mounting once the component will be unmounted and remounted before continuing with the rest of the initial mount. BasePicker creates an Async object in its constructor, and disposes it when unmounted. It also wraps _onResolveSuggestions with a debounced version of itself when mounted.

Together this means _onResolveSuggestions is wrapped with debounce twice; once correctly and once with a disposed Async instance which turns it into a noop. Therefore _onResolveSuggestions never gets called.

New Behavior

Async is created and disposed on mount and unmount respectively. Not in the constructor.

_onResolveSuggestions is only wrapped with debounce once, replacing the original wrapped version rather than applying on top of it.

Related Issue(s)

@andyrooger
Copy link
Contributor Author

I haven't added any tests for this. I don't think I can repeat the behaviour manually without putting this into react 18 with strict mode... but if anyone has suggestions I can try.

@andyrooger andyrooger force-pushed the 25441-onresolvesuggestions-not-triggered branch from 26827a7 to 00b8870 Compare June 15, 2023 12:24
@fabricteam
Copy link
Collaborator

fabricteam commented Jun 15, 2023

📊 Bundle size report

🤖 This report was generated against 02c7384de10ee35cc4db1a2132c32de59db58e1f

@andyrooger
Copy link
Contributor Author

@microsoft-github-policy-service agree

@size-auditor
Copy link

size-auditor bot commented Jun 15, 2023

Asset size changes

Project Bundle Baseline Size New Size Difference
office-ui-fabric-react fluentui-react-Pickers 283.99 kB 284.023 kB ExceedsBaseline     33 bytes

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

Baseline commit: 02c7384de10ee35cc4db1a2132c32de59db58e1f (build)

@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 00b8870:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration
quizzical-forest-cxzys5 Issue #25441

@fabricteam
Copy link
Collaborator

🕵 fluentuiv8 No visual regressions between this PR and main

@fabricteam
Copy link
Collaborator

Perf Analysis (@fluentui/react)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
BaseButton mount 607 577 5000
Breadcrumb mount 1581 1574 1000
Checkbox mount 1619 1606 5000
CheckboxBase mount 1390 1399 5000
ChoiceGroup mount 2773 2775 5000
ComboBox mount 618 617 1000
CommandBar mount 5845 5802 1000
ContextualMenu mount 11180 11139 1000
DefaultButton mount 732 703 5000
DetailsRow mount 2076 2058 5000
DetailsRowFast mount 2062 2083 5000
DetailsRowNoStyles mount 1890 1902 5000
Dialog mount 2616 2483 1000
DocumentCardTitle mount 213 207 1000
Dropdown mount 1886 1861 5000
FocusTrapZone mount 1062 1086 5000
FocusZone mount 987 992 5000
GroupedList mount 39258 39365 2
GroupedList virtual-rerender 18980 19151 2
GroupedList virtual-rerender-with-unmount 47881 47634 2
GroupedListV2 mount 221 210 2
GroupedListV2 virtual-rerender 190 200 2
GroupedListV2 virtual-rerender-with-unmount 214 205 2
IconButton mount 1008 1015 5000
Label mount 302 314 5000
Layer mount 2577 2603 5000
Link mount 374 370 5000
MenuButton mount 868 868 5000
MessageBar mount 20299 20163 5000
Nav mount 1837 1862 1000
OverflowSet mount 723 729 5000
Panel mount 1690 1708 1000
Persona mount 712 702 1000
Pivot mount 808 820 1000
PrimaryButton mount 810 792 5000
Rating mount 4313 4376 5000
SearchBox mount 862 847 5000
Shimmer mount 1778 1769 5000
Slider mount 1262 1257 5000
SpinButton mount 2683 2641 5000
Spinner mount 366 372 5000
SplitButton mount 1724 1706 5000
Stack mount 390 394 5000
StackWithIntrinsicChildren mount 824 804 5000
StackWithTextChildren mount 2499 2447 5000
SwatchColorPicker mount 5752 5710 5000
TagPicker mount 1370 1294 5000
Text mount 347 350 5000
TextField mount 871 876 5000
ThemeProvider mount 768 795 5000
ThemeProvider virtual-rerender 568 556 5000
ThemeProvider virtual-rerender-with-unmount 1202 1202 5000
Toggle mount 585 576 5000
buttonNative mount 186 176 5000

@andyrooger andyrooger marked this pull request as ready for review June 15, 2023 12:56
@andyrooger andyrooger requested review from a team as code owners June 15, 2023 12:56
@marcosmoura marcosmoura removed their assignment Apr 12, 2024
@khmakoto khmakoto merged commit 2a31760 into microsoft:master Sep 9, 2024
marcosmoura added a commit to marcosmoura/fluentui that referenced this pull request Sep 12, 2024
* master: (77 commits)
  fix(react-drawer): update scroll state when children changes (microsoft#32818)
  feat(react-storybook-addon): improve addon to more readable names (microsoft#32815)
  chore: cleanup react-carousel-preview (microsoft#32475)
  feat(storybook): add rtl/ltr toggle storybook addon (microsoft#32814)
  Carousel: Storybook updates and fixing exports/focus (microsoft#32457)
  release: applying package updates - react v8
  release: applying package updates - web-components
  Update d3 dependency versions to 3.x.x and 4.x.x (microsoft#32463)
  RFC: Extended Design Tokens for Fluent UI React (microsoft#32058)
  update doc to reflect setTheme function change (microsoft#32490)
  fix (react-dialog): Use consistent rounding for clientHeight and innerHeight (microsoft#32480)
  fix(public-doscite-v9): global styles should not be applied to story elements (microsoft#32472)
  feat(workspace-plugin): implement verify-packaging executor (microsoft#32403)
  release: applying package updates - react-components
  Add strokeDasharray property when optimizeLargeData is true (microsoft#32494)
  fix(TreeItemLayout): Actions should not unmount between successive mouse events (microsoft#32477)
  release: applying package updates - react v8
  bugfix(react-tree): recover from tabIndex=-1 when TreeItem is removed (microsoft#32442)
  Fix onResolveSuggestions not being called after component is remounted in react 18 strict mode (microsoft#28227)
  fix(codeowners): update most packages owned by cxe-red with cxe-prg (microsoft#32445)
  ...
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.

[Bug]: TagPicker onResolveSuggestions not triggered in React 18 using createRoot

5 participants