Overview

Since Canvas 1.4.x, any component that uses $ref: json-schema-definitions:// URIs in its schema causes the following uncaught JavaScript error in the browser, crashing all Canvas component forms on the page:

Uncaught Error: NOT SUPPORTED: keyword "id", use "$id" for schema ID at Object.code (index.js?v=1.4.1:414:55067)

Root cause

When PHP resolves a $ref URI via justinrainbow/json-schema, UriRetriever::retrieve() sets id: on the schema object. This is draft-04 JSON Schema behavior.

Canvas 1.4.x upgraded AJV to v8, which no longer accepts the draft-04 id keyword (only $id). GeneratedFieldExplicitInputUxComponentSourceBase::stripNon StandardJsonSchemaKeys() strips meta:enum and x-translation-context before sending schemas to the browser, but does not strip id. The result is that id reaches the browser and AJV v8 throws.

This is not limited to contrib or custom modules - Canvas's own schema.json has nested $ref URIs (e.g. the image and video definitions both reference json-schema-definitions://canvas.module/image-uri), so any component using those well-known shapes is affected.

Note that PropShape::normalizePropSchema() already strips id and even has a comment explaining exactly why (// Omit the ID containing the resolved $ref URI). This fix was simply not applied to stripNonStandardJsonSchemaKeys() when AJV was upgraded.

Steps to reproduce

  1. Install Canvas 1.4.x
  2. Use any SDC component with a prop using $ref: json-schema-definitions://canvas.module/image (or any other json-schema-definitions:// URI)
  3. Open the Canvas page builder
  4. Observe: Uncaught Error: NOT SUPPORTED: keyword "id" in browser console; component form is non-functional

Fix

In GeneratedFieldExplicitInputUxComponentSourceBase::stripNonStandardJsonSchemaKeys(), add 'id' to the keys to remove:

$keys_to_remove = ['meta:enum', 'x-translation-context', 'id'];

Patch and MR attached.

Issue fork canvas-3591133

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

zeeshan_khan created an issue. See original summary.

zeeshan_khan’s picture

Patch..

zeeshan_khan’s picture

Status: Active » Needs review

penyaskito’s picture

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.