-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Prerequisites
- I have read the documentation;
- In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
Description
When the enum list is being asynchronously retrieved enumOptions can come through as a boolean "false" ... at least it can for me with my changes. I suspect it's possible for others as well. It's quite obvious with the next proposed enhancement I'm panning on submitting, but possibly harder to reproduce in the current codebase.
The fix is to convert that "false" value back to an empty array so that the enumOptions.map will not error in the render. The list will temporarily be empty, but better that than erroring and never filling.
The offending line is in StringField.js:
const enumOptions = (schema.enumOptions || Array.isArray(schema.enum)) && optionsList(schema);
As a result enumOptions can effectively become a "false" boolean.
var enumOptions = (schema.enumOptions || Array.isArray(schema.enum)) && optionsList(schema);
if (!enumOptions) {
enumOptions = [];
}
enumOptions will still evaluate to false, but when it come to the render routine later and it attempts enumOptions.map it won't error.
Later when the data is available it will display correctly.
Steps to Reproduce
- [First Step]
Well, I have a GraphQL query returning data directly into the form.
Even if it's hard to reproduce, I'd suggest that it makes sense to try and keep it typed as an array at all times regardless.
Expected behavior
I think enumOptions should never be a boolean. It can safely be an empty array and still evaluate as false.
Actual behavior
On the initial render for me enumOptions evaluated as "false" while waiting for the GraphQL query to return data. These then failed in the render on the control when it tried to do enumOptions.map on a boolean.
Version
Latest