Issue #3732💬 AnsweredOpened August 27, 2021by aliibrahim1230 reactions

Comment component type do not support adding traits

Quick answerby aliibrahim123

@artf

Read full answer below ↓

Question

i am working on a script that add a trait on all the component type , but the comment type do not have the prototype object. code

        ddw = editor.DomComponents.getTypes();
	
	 for (let i = 0; i < ddw.length; i++) {
	
	ddq = ddw[i].id;
	editor.DomComponents.addType(ddq, {
    model: editor.DomComponents.getType(ddq).model.extend({
      defaults: Object.assign({}, editor.DomComponents.getType(ddq).model.prototype.defaults, {
        
        traits: editor.DomComponents.getType(ddq).model.prototype.defaults.traits.concat([
          'hallo'
        ])
      })
    })
	
    view: editor.DomComponents.getType('text').view
	 });}

Answers (4)

aliibrahim123August 27, 2021

@artf

artfAugust 29, 2021

Don't use model.extend/view.extend, those are part of the old API. This is an example of how properly extend traits on all components

const { Components } = editor;
Components.getTypes().forEach(({ id, model }) => {
    Components.addType(id, {
        model: {
            defaults: {
              traits: [ ...model.getDefaults().traits, 'new-trait', ]
            },
        },
    })
});
ClaudeCodeMay 17, 2026

Thanks for reporting this, @aliibrahim123.

Thanks for sharing your report about comment component type do not support adding traits. To help the team investigate and prioritize this:

Please provide:

  1. A minimal reproducible example (CodeSandbox/JSFiddle)
  2. Your GrapesJS version number
  3. Browser and OS information
  4. Any error messages from the browser console
  5. Steps to reproduce the issue

What helps most:

  • Minimal code example (not your full project)
  • Screen recording or screenshot showing the issue
  • Expected vs actual behavior clearly stated
  • GrapesJS configuration you're using

With these details, the maintainers can identify and prioritize a fix much faster. The GrapesJS team is very responsive to well-documented issues.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.