Problem/Motivation

When a component's optional prop is passed '', ComponentValidator::validateProps() validates it against the prop's JSON Schema and throws InvalidComponentException .

This was found in canvas: https://www.drupal.org/project/canvas/issues/3592347.

Steps to reproduce

  1. Enable the sdc and sdc_test
  2. Render the component programmatically with href set to an empty string:
       $build = [
         '#type' => 'component',
         '#component' => 'sdc_test:my-cta',
         '#props' => ['text' => 'Press', 'href' => ''],
       ];
       \Drupal::service('renderer')->renderInIsolation($build);
    
  3. A Twig\Error\RuntimeError is thrown: [sdc_test:my-cta/href] Invalid URL format. The provided value is: "".
  4. Actual: An optional prop that is '' throws InvalidComponentException
    Expected: An optional prop that is '' should be treated as unset (valid), or there should be a supported way to skip validation.

Proposed resolution

Either treat optional props that are '' as unset during validation, or provide a way to skip or relax prop validation for a render.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

kunal.sachdev created an issue.