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
Input should behave like normal AutocompleteInput. Same as without using useChoicesContext, options don't flicker, input doesn't clear itself after network call.
What happened instead:
After network call is made to ReferenceInput's reference, the input clears, the dropdown show previous options and then flickers the filtered options.
Steps to reproduce:
Go to any PostEdit, first input is Test users, type in something, then the flickering and input text clear happen.
Playing a bit with your stackblitz, I was able to narrow it down to the fact that the React Element passed to optionText needs to be memoized (or a constant).
I.e. the following makes the flicker disappear:
constmemoizedOptionUser=<OptionUser/>;exportconstUserAutocompleteInput=()=>{// When I comment out useChoicesContext it behaves correctlyconstchoices=useChoicesContext();useEffect(()=>{console.log(choices.allChoices);},[choices]);return(<AutocompleteInputlabel="Select flickering user"optionText={memoizedOptionUser}inputText={inputText}matchSuggestion={matchSuggestion}/>);};
This can be your workaround for now.
It would be better if we could memoize the Element on our end though, so I'll mark this as a bug and we'll take some time to dig into it.
Caution:<SimpleFormIterator>clones its children several times, as it needs to override their actual source for each record. If you use a custom Input element, make sure they accept a custom source prop.
Can you share a bit more about what you're trying to achieve? I fail to understand why you would call useChoicesContext without using any of the values it returns
What you were expecting:
Input should behave like normal
AutocompleteInput
. Same as without usinguseChoicesContext
, options don't flicker, input doesn't clear itself after network call.What happened instead:
After network call is made to
ReferenceInput
'sreference
, the input clears, the dropdown show previous options and then flickers the filtered options.Steps to reproduce:
Go to any
PostEdit
, first input isTest users
, type in something, then the flickering and input text clear happen.Related code:
https://stackblitz.com/edit/github-jnpt6d?file=src%2Fposts%2FUserReferenceInput.tsx,src%2Fposts%2FPostEdit.tsx,src%2Fposts%2FUserAutocompleteInput.tsx
Go to any
src/posts/PostEdit.tsx
, first input isinside
UserReferenceInput
there isUserAutocompleteInput
which reproduces the issue.The bug is reproducible when
UserAutocompleteInput
uses both:useChoicesContext
to somehow read the choicesoptionText
,inputText
andmatchSuggestion
functionality.I tried passing all the props or forwarding the ref which didn't help.
Environment:
The text was updated successfully, but these errors were encountered: