Compatibility of ComponentMetadataRequirementsChecker with SDC themes

Created on 14 October 2025, 7 days ago
Updated 15 October 2025, 6 days ago

Overview

While testing Canvas with contrib & custom SDC themes, I have notice than most of our SDC are not loaded and land in Disabled & incompatible components tab.

A prop may not be of type "object" unless it has a $ref defined.

      if ($prop['type'][0] === 'object' && !isset($prop['$ref'])) {
        $messages[] = \sprintf('Prop "%s" is of type "object" without a $ref, which is not supported', $prop_name);
        continue;
      }

In JSON schema, $ref and type can technically be met together but they normally don't because the schema resolver is merging the $ref into the current position, bringing the type with it.

So, expecting to have a type: object alongside the $ref is a bit weird and no a lot of SDC themes (except the ones knowing about this Canvas requirement) will have this.

Required props must have examples.

      if (in_array($prop_name, $required_props, TRUE) && !isset($prop['examples'][0])) {
        $messages[] = \sprintf('Prop "%s" is required, but does not have example value', $prop_name);
      }

In JSON Schema, examples (like title, description...) is a metadata only for documentation and must not be part of processing.

There is already a JSON property for this: default which must be used for default value in forms but can also be used for default value while dropping a component.

Moreover, default is a single value property, and there is no need on picking the first item like what Canvas is currently doing with examples.

And we can avoid this quirk because JSON schema is expecting default value to be valid:

JSON Schema does not require that examples must be valid, but we do require the first one to be, as we use it as the default value for the prop.

See also 🐛 DX & authoring experience: for SDC+code components, the example is treated as the default, may not be desirable Active

Canvas always requires schema, even for theme components.

    if ($metadata->schema === NULL) {
      throw new ComponentDoesNotMeetRequirementsException(['Component has no props schema']);
    }

A lot of SDC in the wild have only slots, so they don't have a props schema. Why not just adding the schema on the fly (or better, fixing the root cause leading to this restrictions) instead of being incompatible with them?

Proposed resolution

  • Drop the first and third requirement
  • Move the second requirement to default instead of examples
🐛 Bug report
Status

Active

Version

1.0

Component

Component sources

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
  • Needs product manager review

    It is used to alert the product manager core committer(s) that an issue represents a significant new feature, UI change, or change to the "user experience" of Drupal, and their signoff is needed. If an issue significantly affects the usability of Drupal, use Needs usability review instead (see the governance policy draft for more information).

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024