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

  1. On a site without canvas_test_article_fields, create a non-canvas_page bundle (e.g. a Page node type) and one node of it.
  2. In Canvas, create a Full content template for that bundle and add a component.
  3. Click Preview.
  4. 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.
  5. With this MR: the preview renders, and Exit Preview returns to the editor.

Notes for reviewers

  • The existing Add templates to page test previews an article template and kept passing because canvas_test_article_fields adds a component-tree field to article, which makes ComponentTreeLoader allow-list that bundle — masking the bug. The new test deliberately avoids that module.
  • No backend change: the canvas_page-only restriction in ComponentTreeLoader is 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

Merge request reports

Loading