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
- Install Canvas 1.4.x
- Use any SDC component with a prop using $ref: json-schema-definitions://canvas.module/image (or any other json-schema-definitions:// URI)
- Open the Canvas page builder
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | canvas-3591133-strip-id-keyword-ajv-v8.patch | 1.34 KB | zeeshan_khan |
Issue fork canvas-3591133
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
Comment #2
zeeshan_khan commentedPatch..
Comment #3
zeeshan_khan commentedComment #5
penyaskitoNice timing 😅
See #3591028: Consistently use JSON-Schema Draft-07 dialect in frontend and backend by updating `justinrainbow/json-schema` to ^6.8.0