Overview
When I try to give a prompt to create/generate a new component AI is not able to do that. I am getting the below error
Error: There was an error compiling your code.
Check your browser's developer console for more details.
We should fix the following issues as well as they also requires updating the system prompt of the agent.
#3584114: Canvas AI: Import Image from drupal-canvas instead of next-image-standalone:
AI agent uses deprecated next-image-standalone import
The Canvas Component Agent's system instructions still tell the AI to import the Image component from next-image-standalone, which is now deprecated. A prior issue changed the correct import source to drupal-canvas, but the agent's YAML config was never updated to reflect this. Any component the AI generates that uses an image will use the wrong import.
#3558216: Canvas AI: Unable to edit code components:
AI is unable to edit existing code components
When a user asks the Canvas AI to edit an existing code component, the agent responds with "The 'edit component' functionality is only available on component edit route." The edit action simply does not work, making it impossible to use AI to modify components that have already been created.
#3564656: AI continues to use unsupported React libraries while creating a component:
AI keeps importing unsupported external React libraries
Even though a previous fix was made to give the AI context about which libraries are available in Canvas, the AI still imports external libraries not supported by Canvas (e.g., dompurify). This causes the component preview to fail to load entirely. The AI is not respecting the library constraints provided in its instructions.
#3551659: AI can generate invalid code components: props' names may reuse slots' names:
AI generates invalid code
When the AI generates a code component, it sometimes creates prop names that conflict with existing slot names, producing invalid code. These invalid props don't appear in the UI, so the user has no way to detect or fix them manually. The component appears to save fine but is broken under the hood.
Please refer the screenshots.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | Drupal-Canvas-04-21-2026_12_28_PM.png | 93.85 KB | akhil babu |
| image (11).png | 871.36 KB | subbu94 | |
| image (10).png | 634.56 KB | subbu94 |
Issue fork canvas-3584136
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 #4
sethu_sk commentedDrupal canvas AI is generating the react based code without following proper syntax like classname instead of className and "" tag instead of "
"
Comment #5
akhil babuThanks for working on this. There are some more issues reported for the code component agent. We should consolidate all the ones that need system prompt update and fix in one go. I will link those issues here.
#3551659: AI can generate invalid code components: props' names may reuse slots' names
#3584114: Canvas AI: Import Image from drupal-canvas instead of next-image-standalone
#3558216: Canvas AI: Unable to edit code components
#3564656: AI continues to use unsupported React libraries while creating a component
Comment #6
akhil babuComment #7
akhil babuComment #8
akhil babuComment #9
akhil babuStructure of the current prompt
1. Agent Identity & Role
2. Context Tokens (Replaced at Runtime)
[canvas_ai:menu_fetch_source]— determines how menus are fetched. Possible values:linkset_not_configured,menu_fetching_functionality_not_available,jsonapi_menu_items,linkset.[canvas_ai:json_api_module_status]— whether JSON:API module is enabled or disabled. Possible values:enabled,disabled.[canvas_ai:selected_component]— the ID of the currently selected component, or null.[canvas_ai:selected_component_required_props]— array of prop IDs currently marked as required on the selected component.[canvas_ai:custom_libraries]— JSON object of available custom library code snippets.3. Critical Flow Gatekeeper (Routing Logic)
[canvas_ai:selected_component]is null → STOP immediately. Respond with the exact string: "The 'edit component' functionality is only available on component edit route." No extra text, no tools, no further processing.[canvas_ai:selected_component]is not null → follow Component Edit Flow.4. Component Naming Directive
5. Props Directive (Comprehensive)
props_metadataJSON array when creating or editing a component. No exceptions.props_metadatamust have an entry for every variable in the component function signature. One-to-one match required.mainHeading).derived_proptypescontext as the source for prop type structures. Only select from that list.6. Color and Style Variants Directive
props_metadatausingderivedType: "listText"with anenumof human-readable option names only (never raw Tailwind classes in enum).class-variance-authority(CVA) library. Tailwind class mappings go inmeta:enum, not inenum.7. Library Reuse Directive
custom_librariesJSON context.8. Data Fetching Directive
9. Content Fetching (Sub-directive of Data Fetching)
json_api_module_statuscontext first."To fetch content data, please enable the JSON:API module.. Because of this, I am unable to [Describe the original user request]."No further processing.ai_agent_get_node_fieldstool to retrieve fields and reference fields.addInclude()..valueor.processed).useSWR,JsonApiClient,DrupalJsonApiParamsfor fetching.attributesorrelationshipsunless confirmed.field_.10. Menu Fetching (Sub-directive of Data Fetching)
menu_fetch_sourcecontext first.JsonApiClient,useSWR, andsortMenufrom@/lib/jsonapi-utils./system/menu/[menu-machine-name]/linksetwithsortMenufrom@/lib/drupal-utils.custom-menu)._childrenand_hasSubmenuproperties, recursively.11. Image Directive
<Image>component fromnext-image-standalone. Never use HTML<img>.{ src, alt, width, height }and spread it.next-image-standalone.12. Component Create Flow (Tool Sequence)
ai_agent_create_componentonly when no selected component exists in the request.ai_agent_create_componentto create the component, providing CSS, JS, component structure, and props metadata.13. Component Edit Flow (Tool Sequence)
ai_agent_get_js_componentto get the current JS and CSS. If no component name is provided, use[canvas_ai:selected_component].ai_agent_edit_component_jsto submit JS changes.[canvas_ai:selected_component].derived_proptypescontext for supported structure.selected_component_required_propsas-is to the edit tool without modifications.14. Tools Referenced
ai_agent_create_component— creates a new component.ai_agent_get_js_component— retrieves the current JS and CSS of a component.ai_agent_edit_component_js— submits edited JS for a component.ai_agent_get_node_fields— retrieves fields and reference fields for a content type.15. Tailwind CSS Rules
classNameattributes only.@applyin component code.16. Code Quality Rules
React.prefix.17. Final Response Rules
Comment #10
rakhimandhania commentedComment #11
akhil babuSo, I asked the agent to create a banner component. The prompt was:
"Create a banner code component with a yellow background and large, block, all-caps text for the banner content."
The component got generated with this code.
But it's colors were not rendered. Looks like none of the tailwind styles are getting applied :(.
Update:
The component styles were not rendred due to the following issues with the code given by the agent.
1. It used
classnameinstead ofclassName2.
<div className="{bannerStyles()}"is wrong JSX. It should be just<div className={bannerStyles()}This was correctly identified by @sethu_sk (See #4)
Comment #12
akhil babuI found another issue. The model provides the correct input value "className" in the code. However, when the tool inputs pass through
Drupal\ai\Service\HostnameFilter, the HostnameFilter::filterText method sanitizes this input and converts "className" to "classname".This can be verified by asking the agent to generate a component, after adding the following line to settings.php
Comment #13
sethu_sk commentedAfter enabling the full_trust_mode in settings.php file, able to see, the components are created with proper syntax, thanks @akhil babu.
Comment #14
akhil babuAI Agents module has added a fix for this. Please see: https://git.drupalcode.org/project/ai_agents/-/work_items/3585986#note_8...
It adds a new option for AI agents to disable the hostname filtering. Once AI Agents get a release with this fix, we should enable that option for the component agent.