SDCs with optional images without examples cannot be placed

Created on 9 April 2025, 8 days ago

Overview

Currently we require SDCs to provide examples if they are using optional images, because in order to render an optional image we need at least something to render.

The xb_test_sdc SDC image-optional-without-example currently fails when dragged into the canvas. The PATCH request to /xb/api/form/component-instance/node/1 returns 400 Bad Request with an unhelpful body: {"errors":[""]}

This is because of this code in GeneratedFieldExplicitInputUxComponentSourceBase::buildConfigurationForm():

      if ($prop_source_array === NULL) {
        // The client didn't send this prop but should. This is an error OR the
        // data has been tampered with.
        throw HttpException::fromStatusCode(Response::HTTP_BAD_REQUEST);
      }

The client correctly didn't send any props, but we also didn't fall back to a default image, because we don't have one.

Proposed resolution

One of the following:

  1. Mark SDCs with optional images and no examples as invalid, so they do not appear in the component library
  2. Provide a system wide default/fallback image for SDCs without examples

Additionally, improve the error that is thrown on that line so that the API response is useful if this occurs in another situation - we should at least name the problematic prop, for example.

User interface changes

🐛 Bug report
Status

Active

Version

0.0

Component

Component sources

Created by

🇎🇧United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024