Issue #6407πŸ’¬ AnsweredOpened February 16, 2025by gopukinapp0 reactions

Custom traits are not loading inside a custom block

Quick answerby artf

Your component has inner components, so if you select one of those, you will see traits of those components, not event-block. If you properly select event-block, you'll see your traits. <img width="856" alt="Image" src="https://github.com/user-attachments/assets/a0913237-02f9-44f8-af51-6d151b618a37" /> and FYI, this i...

Read full answer below ↓

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Version 133.0.6943.98

Reproducible demo link

https://codesandbox.io/p/sandbox/loving-breeze-mdls43?file=%2Findex.js%3A77%2C6

Describe the bug

Iam trying to add some custom triats to my block unfortunately i can only see the default triats [id,title] my block have few html code but if i remove all the html code and put only one string like hellow world without any html in component property the triats will show


  components: `
          <h2 class="text-2xl font-bold text-gray-800" data-event-title>
            Event Name
          </h2>
          <p class="text-gray-600 mt-2">
            Start Date: <span data-event-start>YYYY-MM-DD</span>
          </p>
          <p class="text-gray-600">
            End Date: <span data-event-end>YYYY-MM-DD</span>
          </p>
        `, when do like this it traits will not come

but

 components: `
        Hello world
        `,
if i put like this all my triats will come


this is my entire block code



const myEventBlockPlugin = (editor, options = {}) => {
  editor.Components.addType("event-block", {
    model: {
      defaults: {
        tagName: "div",
        draggable: true,
        droppable: false,
        attributes: { class: "p-4 bg-white shadow-lg rounded-lg text-center" },
            components: `
          <h2 class="text-2xl font-bold text-gray-800" data-event-title>
            Event Name
          </h2>
          <p class="text-gray-600 mt-2">
            Start Date: <span data-event-start>YYYY-MM-DD</span>
          </p>
          <p class="text-gray-600">
            End Date: <span data-event-end>YYYY-MM-DD</span>
          </p>
        `,
        traits: [
          {
            name: "event-title",
            label: "Event Name",
            type: "text",
            changeProp: true,
          },
          {
            name: "event-start",
            label: "Start Date",
            type: "date",
            changeProp: true,
          },
          {
            name: "event-end",
            label: "End Date",
            type: "date",
            changeProp: true,
          },
        ],
        props: {
          "event-title": "Event Name",
          "event-start": "YYYY-MM-DD",
          "event-end": "YYYY-MM-DD",
        },
      },

      init() {
        this.on("change:event-title", this.updateTitle);
        this.on("change:event-start", this.updateStartDate);
        this.on("change:event-end", this.updateEndDate);
      },

      updateTitle() {
        const title = this.get("event-title");
        this.view.el.querySelector("[data-event-title]").innerText = title;
      },

      updateStartDate() {
        const startDate = this.get("event-start");
        this.view.el.querySelector("[data-event-start]").innerText = startDate;
      },

      updateEndDate() {
        const endDate = this.get("event-end");
        this.view.el.querySelector("[data-event-end]").innerText = endDate;
      },
    },
  });

  editor.Blocks.add("event-block", {
    label: "Event Block",
    content: { type: "event-block" },
    category: "Basic",
  });
};

Code of Conduct

  • I agree to follow this project's Code of Conduct

Answers (2)

artfβ€’ March 5, 2025

Your component has inner components, so if you select one of those, you will see traits of those components, not event-block. If you properly select event-block, you'll see your traits. <img width="856" alt="Image" src="https://github.com/user-attachments/assets/a0913237-02f9-44f8-af51-6d151b618a37" />

and FYI, this

this.view.el.querySelector("[data-event-end]").innerText = endDate;

is only updating the view of the component, so it does not affect the HTML code to export.

ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @gopukinapp.

The issue with Custom traits are not loading inside a custom block appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.

What to try:

  1. Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
  // your operation here
}, 0);
  1. Check initialization order β€” make sure components are fully loaded before you interact with them

  2. Use the editor's event system β€” listen to completion events:

editor.on('component:mount', (component) => {
  // safe to interact with component here
});

Recommended next steps:

  • Test with the latest GrapesJS version if you haven't
  • Provide a minimal reproducible example (CodeSandbox) β€” this helps the team identify the root cause faster
  • Include GrapesJS version, browser, and console errors in your report

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.