fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

BasePicker.updateValue does not check unmount flag in promise.then

Open lijunle opened this issue 9 years ago • 5 comments

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...)

lijunle avatar Mar 07 '17 15:03 lijunle

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('', []);

joschect avatar Mar 09 '17 16:03 joschect

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 avatar Mar 12 '17 13:03 lijunle

@lijunle Debouce would probably a great thing to try.

joschect avatar Mar 22 '17 21:03 joschect

@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

lijunle avatar Oct 12 '17 19:10 lijunle

Misread the above, reopening

erichdev avatar Oct 12 '17 20:10 erichdev