BasePicker.updateValue does not check unmount flag in promise.then
Bug Report
- Package version(s): all
- Browser and OS versions: all
Priorities and help requested (not applicable if asking question):
Are you willing to submit a PR to fix? Yes (I like this question 😄 )
Requested priority: Normal
Describe the issue:
We have a scenario that, the picker is only for once. It means that, user inputs something into the picker and select, we immediately unmount the picker.
However, in BasePicker.updateValue method, the resolve logic is async and in some case, the last promise is resolved after user select the item and DOM unmounted. In such case, there is no unmount check in promise.then and cause runtime error.
Actual behavior:
Runtime error.
Expected behavior:
No error.
If applicable, please provide a codepen repro:
(If I have time...)
I think that checking for mountedness should be avoided. There are a few solutions that might be easier/better. 1 would be to change the onResolveSuggestions callback that is being provided so that it will return an empty array immediately when an empty string is supplied. Another option is to change the completeSuggestion method so that it no longer calls this.updateValue('') and instead clears the state by doing something like this.resolveNewValue('', []);
Hi, @joschect
We have a discussion with @dzearing about adding a @debounce decorator (https://github.com/OfficeDev/office-ui-fabric-react/issues/1139). How do you think about this?
@lijunle Debouce would probably a great thing to try.
@erichdev Why closing this? This issue is still there and not fixed.
Here is the code in BasePicker.updateSuggestionsList method:
https://github.com/OfficeDev/office-ui-fabric-react/blob/1b22b3e124172e0438363d6026cf44181ce676d5/packages/office-ui-fabric-react/src/components/pickers/BasePicker.tsx#L328-L330
Misread the above, reopening