Skip canvas_page-only layout requests in content template preview
Closes #3591684 (closed)
What this MR does
In the page-preview React component, template previews no longer fire the two requests that target the generic canvas/api/v0/layout/{entityType}/{entityId} route. That route only supports canvas_page entities (ComponentTreeLoader::getCanvasFieldName() throws for anything else), so for a content template — whose preview entity is e.g. a node — the postPreview POST returned a 500.
Testing steps
- On a site without
canvas_test_article_fields, create a non-canvas_pagebundle (e.g. aPagenode type) and one node of it. - In Canvas, create a Full content template for that bundle and add a component.
- Click Preview.
- Before this MR: a 500 error overlay appears (
For now Canvas only works if the entity is a canvas_page!) and Exit Preview leaves the editor stuck until a hard refresh. - With this MR: the preview renders, and Exit Preview returns to the editor.
Notes for reviewers
- The existing
Add templates to pagetest previews an article template and kept passing becausecanvas_test_article_fieldsadds a component-tree field toarticle, which makesComponentTreeLoaderallow-list that bundle — masking the bug. The new test deliberately avoids that module. - No backend change: the
canvas_page-only restriction inComponentTreeLoaderis intentional (temporary, per https://drupal.org/i/3498525). The bug was the client calling the wrong route, so the fix is client-side.
AI usage
This change — root-cause analysis, the fix, and the regression test — was produced with AI assistance (Claude Opus 4.8) and reviewed by a human before submission. See https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquette/policy-on-the-use-of-ai-when-contributing-to-drupal