You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that the default caching behavior for Select.Async is to create a cache object in the constructor, and then mutate that one object forever:
This means that the cache doesn't clear when the props update, even if the props are changing everything about the input. Here's a simplified reproduction:
The Select autoloads the list of turtles and caches it.
Click on "superheroes", which will update the Select with new props, including a different loadOptions function which should provide a list of superheroes.
Click on the input. You'll see a list of turtles.
I thought the workaround for this would be to include a newly-created cache object as a prop:
<Select.Asynccache={{}}loadOptions={fn}.../>
So that whenever the component was re-rendered with new props, it would get a fresh cache object, and if I wanted something persistent I could pass that instead. But this doesn't work, because componentWillReceiveProps doesn't update the internal cache object, it's set forever in the constructor:
Is the current behavior intentional for some other benefit? If not, it seems like the desired behavior should be to always update the cache in componentWillReceiveProps, along the lines of:
Then, if a user uses the default caching behavior, it will have the current behavior, but they at least have the ability to ensure that a cache object they specify as a prop actually becomes the cache on updates and not just during the first construction.
If this makes sense to you I can work up a PR.
The text was updated successfully, but these errors were encountered:
We recommend maintaining your own v1 fork if you want to address v1 issues. We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest versions.
I've noticed that the default caching behavior for
Select.Async
is to create a cache object in the constructor, and then mutate that one object forever:https://github.com/JedWatson/react-select/blob/master/src/Async.js#L56
This means that the cache doesn't clear when the props update, even if the props are changing everything about the input. Here's a simplified reproduction:
https://codepen.io/anon/pen/JpZzzY
loadOptions
function which should provide a list of superheroes.I thought the workaround for this would be to include a newly-created cache object as a prop:
So that whenever the component was re-rendered with new props, it would get a fresh cache object, and if I wanted something persistent I could pass that instead. But this doesn't work, because
componentWillReceiveProps
doesn't update the internal cache object, it's set forever in the constructor:https://github.com/JedWatson/react-select/blob/master/src/Async.js#L75-L81
Is the current behavior intentional for some other benefit? If not, it seems like the desired behavior should be to always update the cache in
componentWillReceiveProps
, along the lines of:Then, if a user uses the default caching behavior, it will have the current behavior, but they at least have the ability to ensure that a cache object they specify as a prop actually becomes the cache on updates and not just during the first construction.
If this makes sense to you I can work up a PR.
The text was updated successfully, but these errors were encountered: