Overview

By following this issue, creating a code component with AI Chatbot, the 2 first times it doesn't complete, the third time it worked as expected.
In the command line we can see the component HTML is created succesfully, but user is not redirected to new code created page.

In drupal log we see this Experience Builder error, for this endpoint : /xb/api/v0/config/js_component

Drupal\experience_builder\Exception\ConstraintViolationException: Validation errors exist: Object(Drupal\Core\Entity\Plugin\DataType\ConfigEntityAdapter): Unable to find class/interface "function" specified in the prop "onButtonClick" for the component "experience_builder:herobanner". Object(Drupal\Core\Entity\Plugin\DataType\ConfigEntityAdapter).props.onButtonClick.type: The value you selected is not a valid choice. (code 8e179f1b-97aa-4560-a02f-2a8b42e49df7) in Drupal\experience_builder\Controller\ApiConfigControllers->validate() (line 207 of /var/www/html/web/modules/contrib/experience_builder/src/Controller/ApiConfigControllers.php).

In console, we can see first the component was created

{
    "status": true,
    "message": "The \u0022HeroBanner\u0022 component has been created. It features a red background, customizable main text, and a call-to-action button. You can control the displayed text and button label, and provide a custom action for the button via the props.\n\nComponent code:\n```jsx\nexport default function HeroBanner({ mainText = \u0022Welcome to our site!\u0022, buttonText = \u0022Get Started\u0022, onButtonClick = null }) {\n  return (\n    \u003Csection className=\u0022bg-red-600 py-16 text-white text-center\u0022\u003E\n      \u003Cdiv className=\u0022container mx-auto px-4\u0022\u003E\n        \u003Ch1 className=\u0022text-4xl font-bold mb-6\u0022\u003E{mainText}\u003C\/h1\u003E\n        \u003Cbutton\n          className=\u0022bg-white text-red-600 font-semibold px-8 py-3 rounded shadow-md hover:bg-red-100 hover:text-red-700 transition-colors duration-200\u0022\n          onClick={onButtonClick}\n        \u003E\n          {buttonText}\n        \u003C\/button\u003E\n      \u003C\/div\u003E\n    \u003C\/section\u003E\n  );\n}\n```\n\nProps metadata:\n```json\n[\n  {\n    \u0022id\u0022: \u0022mainText\u0022,\n    \u0022name\u0022: \u0022mainText\u0022,\n    \u0022type\u0022: \u0022string\u0022,\n    \u0022example\u0022: \u0022Welcome to our site!\u0022,\n    \u0022format\u0022: null,\n    \u0022$ref\u0022: null,\n    \u0022derivedType\u0022: \u0022text\u0022\n  },\n  {\n    \u0022id\u0022: \u0022buttonText\u0022,\n    \u0022name\u0022: \u0022buttonText\u0022,\n    \u0022type\u0022: \u0022string\u0022,\n    \u0022example\u0022: \u0022Get Started\u0022,\n    \u0022format\u0022: null,\n    \u0022$ref\u0022: null,\n    \u0022derivedType\u0022: \u0022text\u0022\n  },\n  {\n    \u0022id\u0022: \u0022onButtonClick\u0022,\n    \u0022name\u0022: \u0022onButtonClick\u0022,\n    \u0022type\u0022: \u0022function\u0022,\n    \u0022example\u0022: \u0022() =\u003E alert(\u0027Button clicked!\u0027)\u0022,\n    \u0022format\u0022: null,\n    \u0022$ref\u0022: null,\n    \u0022derivedType\u0022: \u0022function\u0022\n  }\n]\n```\nThis HeroBanner is now ready for use. Just set the mainText, buttonText, and optionally provide an onButtonClick action for full functionality.",
    "component_structure": {
        "name": "HeroBanner",
        "machineName": "herobanner",
        "status": false,
        "source_code_js": "export default function HeroBanner({ mainText = \u0022Welcome to our site!\u0022, buttonText = \u0022Get Started\u0022, onButtonClick = null }) {\n  return (\n    \u003Csection className=\u0022bg-red-600 py-16 text-white text-center\u0022\u003E\n      \u003Cdiv className=\u0022container mx-auto px-4\u0022\u003E\n        \u003Ch1 className=\u0022text-4xl font-bold mb-6\u0022\u003E{mainText}\u003C\/h1\u003E\n        \u003Cbutton\n          className=\u0022bg-white text-red-600 font-semibold px-8 py-3 rounded shadow-md hover:bg-red-100 hover:text-red-700 transition-colors duration-200\u0022\n          onClick={onButtonClick}\n        \u003E\n          {buttonText}\n        \u003C\/button\u003E\n      \u003C\/div\u003E\n    \u003C\/section\u003E\n  );\n}",
        "source_code_css": "",
        "compiled_js": "",
        "compiled_css": "",
        "imported_js_components": [],
        "props": {
            "mainText": {
                "title": "mainText",
                "type": "string",
                "examples": [
                    "Welcome to our site!"
                ]
            },
            "buttonText": {
                "title": "buttonText",
                "type": "string",
                "examples": [
                    "Get Started"
                ]
            },
            "onButtonClick": {
                "title": "onButtonClick",
                "type": "function",
                "examples": [
                    "() =\u003E alert(\u0027Button clicked!\u0027)"
                ]
            }
        }
    }
}

But then we see in following request this error

{
    "errors": [
        {
            "detail": "Unable to find class\/interface \u0022function\u0022 specified in the prop \u0022onButtonClick\u0022 for the component \u0022experience_builder:herobanner\u0022.",
            "source": {
                "pointer": ""
            }
        },
        {
            "detail": "The value you selected is not a valid choice.",
            "source": {
                "pointer": "props.onButtonClick.type"
            }
        }
    ]
}

After retrying 2 other times, it worked for

Code component generated by AI

Proposed resolution

User interface changes

CommentFileSizeAuthor
#4 image (10).png251.48 KBheyyo
Screenshot From 2025-06-23 15-11-34.png201.42 KBheyyo

Comments

heyyo created an issue. See original summary.

narendrar’s picture

The created component has an outdated structure, which was changed in #3502640: Camelcase the client-side representation of code components. This could be the cause of the error.

        "source_code_css": "",
        "compiled_js": "",
        "compiled_css": "",

Pulling the latest changes from the 0.x branch, rebuilding the front-end with npm install && npm run build and clearing the cache might help resolve the issue.

Please let me know if the problem persists.

wim leers’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

Agreed with Naren!

heyyo’s picture

StatusFileSize
new251.48 KB

Just to inform you, even with newer commit of XB(#a3799e20d3) I have the same exact issue using OpenAI
With those versions:

        "drupal/ai": "^1.1",
        "drupal/ai_agents": "^1.1",
        "drupal/ai_provider_openai": "^1.1",

On this callback /xb/api/v0/config/js_component, I received this status code 422 Unprocessable Entity

With this error:

{
    "errors": [
        {
            "detail": "Unable to find class\/interface \u0022function\u0022 specified in the prop \u0022onButtonClick\u0022 for the component \u0022experience_builder:herobanner\u0022.",
            "source": {
                "pointer": ""
            }
        },
        {
            "detail": "The value you selected is not a valid choice.",
            "source": {
                "pointer": "props.onButtonClick.type"
            }
        }
    ]
}

After step debugging the code it shows the validation of ApiConfigControllers:validate fails because of the react component generated by OpenAI which contains an onButtonClick without declaring it...

Surprise of OpenAI...

heyyo’s picture

Status: Postponed (maintainer needs more info) » Needs work

Project: Experience Builder » Drupal Canvas
Version: 0.x-dev » 1.x-dev

Experience Builder has been renamed to Drupal Canvas in preparation for its beta release. You can now track issues on the new project page.

narendrar’s picture

Status: Needs work » Closed (cannot reproduce)

@heyyo, I am closing this for now, but please feel free to re-open if you can still reproduce it on a fresh install

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.