Overview

When a component’s Twig template contains a render error (for example, referencing a property before it is defined), the component appears greyed out in the Canvas component list and cannot be added to the page.

However:

  • The component still appears in the “Available component list” on /admin/appearance/components
  • There are no clear error messages on the Canvas UI
  • There is no indication why the component is disabled
  • The “Disabled & incompatible components” tab does not provide actionable information in this scenario

This makes debugging confusing and time-consuming. In my case, the issue was caused by using a property in Twig before defining it in the component schema. It took some investigation to understand why the component was greyed out.

Steps to reproduce

  • Create a Canvas component with a valid .component.yml
  • Introduce a Twig render error (e.g. reference a prop that is not defined in the schema)
  • Clear cache
  • Open Canvas and try to add the component


Current behaviour

  • Component appears greyed out in the Canvas component list
  • No visible error or explanation in the UI
  • No hint that the issue originates from a Twig render error


Proposed behaviour

If a component cannot be rendered due to a Twig/render error, Canvas should:

  • Display a visible warning or error indicator next to the component name (warning icon is already there btw)
  • Provide an explanatory tooltip when hovering the greyed component
  • Optionally show a short message like: "Component cannot be rendered due to Twig/render error. Check logs for details" or similar. Ideally expose the actual error message (when in dev mode). Even a minimal hint (e.g. “Render error detected”) would significantly improve the debugging experience.

Comments

spleshka created an issue. See original summary.

spleshka’s picture

Issue summary: View changes
wim leers’s picture

Hi @spleshka — long time no see! 😄

Thanks for creating this issue. However … I cannot reproduce it. We specifically did a lot of work around making sure the DX around all this is good & helpful 😬 See

If I place the test SDC at tests/modules/canvas_test_sdc/components/simple/heading and hack its Twig to be invalid:

<h1>Hi {{ name|invalidFilter }}</h1>

I see this:

(Because I'm a developer and hence have verbose error logging turned on. See the screenshots in the issue summary of #3485878: Server-rendered component instances should NEVER result in a user-facing error, should fall back to a meaningful error instead (+ log) — that illustrates what you should see when verbose error logging is turned off.)

  1. 👆I suspect that if you'd have seen that, you wouldn't have filed this issue? Is that what you expected?
  2. 🙏 It seems like you found a way to bypass all those protection layers, can you share the exact code that allows you to reproduce this? (I'm assuming you tested on 1.1.0 of Canvas.)
spleshka’s picture

Hi @Wim, indeed nice to see you again in the issue queue 😊.

The issue I had was on the environment with the following component (I've changed the component name for simplicity):

test.component.yml:

'$schema': 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json'
name: Test
props:
  type: object
  properties:
    image:
      title: Image
      $ref: json-schema-definitions://canvas.module/image
      type: object

And the template:

test.twig:

{% include 'canvas:image' with image %}

Component with the issue

For some reason, on my local environment for the client project the component is greyed-out and when I hover over it then just nothing happens (tested on latest versions of Canvas - both 1.1.0 and 1.1.1). However, when I tried to reproduce the same issue (now that you mentioned you can not reproduce it) on another environment (drupal cms from scratch using ddev) and when I hover over the same component the tooltip comes up saying that there's a render error and I should check the logs:

The component with the issue

I'm a bit confused as to what did we do wrong on the client project so that the tooltip does not appear. We didn't hack Canvas, I promise! 😄

I'll continue the investigation and update the issue when the mistery is solved.

spleshka’s picture

Category: Feature request » Support request
Status: Postponed (maintainer needs more info) » Active

Alright, we managed to identify the cause of the issue on our side and wanted to share it here in case it helps others.

The problem turned out to be related to Content Security Policy (CSP) configuration. In our setup we had a fairly strict policy, specifically:

frame-src 'self';

Because of this, the component preview popup in the Canvas sidebar (shown when hovering over components) did not appear. After investigating further, we noticed that Canvas renders the preview inside an iframe generated from a blob: URL. Since our CSP only allowed self, the iframe was being blocked by the browser.

Adding blob: to the frame-src directive resolved the issue:

frame-src 'self' blob:;

Once this was added, the preview popups started working correctly.

I wonder is there any recommended CSP configuration for Canvas to ensure that all of its UI features work correctly? If not, it might be useful to convert this issue (or a follow-up) into documentation describing the minimum CSP directives required for Canvas, since many sites using Canvas are likely to run with stricter CSP policies.

bnjmnm’s picture

Status: Active » Closed (outdated)

@spleshka the blob usage was removed in 1.x ~2 weeks ago in this issue #3575072: Component preview doesn't work for code components in Safari. The reported issue it addressed had slightly different symptoms, but was also related to CSP. It is part of Canvas 1.2.0.

I'm closing as outdated, but by all means reopen if this does not address the problem.

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.

spleshka’s picture

That's great news, thank you @bnjmnm.