Overview
It's currently possible to create a JavaScript component config entity with an invalid example string prop value by using an empty string.
An error was reported that happened at cache clear, but there might be other cases where this causes issues:
In StaticPropSource.php line 242:
[LogicException]
Drupal\canvas\PropSource\StaticPropSource::withValue called with invalid value for field type field_item:string.
component.yml shape to reproduce the issue:
name: Empty string repro
machineName: empty_string_repro
props:
properties:
delta:
type: string
title: Delta
examples:
- ''
Proposed resolution
User interface changes
n/a
Comments
Comment #2
wim leersSibling of #3586958: Relative image paths are incorrectly allowed as example image prop values in SDCs and code component example values.
Comment #3
wim leersComment #6
longwaveI thought this would end up in the same place as #3586958: Relative image paths are incorrectly allowed as example image prop values in SDCs and code component example values, but it's not quite so can be committed separately.
Comment #7
penyaskitoI fail to remember why an empty example is not valid iff the prop is not required.
Comment #8
wim leers#7: Because:
\Drupal\Core\Field\FieldItemListInterface::filterEmptyItems()+\Drupal\Core\TypedData\ComplexDataInterface::isEmpty(). For example\Drupal\Core\Field\Plugin\Field\FieldType\UriItem::isEmpty()does:… which is directly leading to the exception this issue reported.
Comment #9
wim leers#7: I suspect you're thinking of "empty string is not a valid string enum value" which you worked on.
Comment #10
wim leersComment #11
penyaskitoI definitely had #9 in mind, I failed to see why I wouldn't accept an empty string for a regular string.
So in this case is a core limitation.
Re: Conceptually: I disagree. An empty string would be a good example for reenforcing that it's an optional prop. The problem is that we are using the first one. Wouldn't be an issue if we took the first-not-empty-one as default or if #3514672: [Needs design] DX & authoring experience: support `default` in addition to `examples[0]`, enables updating a component input across all existing instances was completed.
Comment #12
penyaskito+1 to RTBC btw. #11 is out of scope here.
Comment #13
wim leers#11:
You're looking at it from a Canvas end user/Content Author POV. You should look at it here from a component developer POV, because that's the person who is now going to be told to do something differently.
When a SDC or code component prop is marked as optional, it's optional from a JSON Schema POV. Which means "it can be omitted". The absence of a value is not the same as a value considered empty. Which value would you consider "empty" for
type: integer? And which one fortype: string, format: uri?Therefore this is IMHO a slippery slope that will lead to more confusion. I disagree with allowing
''as a valid example value.IOW: this is about code/metadata hygiene. And Canvas' ability to reason about the JSON schema for a given component. This MR has zero impact on end users.
Comment #14
penyaskitoTrue that.
Comment #16
wim leers