Issue #1770Opened January 31, 2019by a-bashtannik2 reactions

[Bug] Components with custom tag are not rendered if specified in theme body

Question

Hello I created very simple skeleton of GrapesJS editor. HTML template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Demo</title>
</head>
<body>
<div id="gjs">
    <test-tag></test-tag>
</div>
</body>
</html>

Javascript:

import 'grapesjs/dist/css/grapes.min.css'
import grapesjs from 'grapesjs';

var editor = grapesjs.init({
    autorender: 0,
    container: '#gjs',
    fromElement: true,
    storageManager: {type: null},
});

// Get DomComponents module
var comps = editor.DomComponents;
var defaultType = comps.getType('default');

comps.addType('test-component-type', {
    model: {
        defaults: {}
    },
    view: {
        tagName: 'div',
        render: function () {
            defaultType.view.prototype.render.apply(this, arguments);
            var element = document.createElement("h1");
            element.innerText = "TEST-COMPONENT OK";
            this.el.appendChild(element);
            return this;
        }
    },

});

editor.render()

editor.BlockManager.add('test-block', {
    label: 'Test Block',
    content: {
        type: 'test-component-type'
    }
});

Result of loading: image As you see, component is not rendered. But if I drop blocks manually, everything is ok: image If I change template and set data-gjs-type attribute to <test-tag data-gjs-type="test-component-type"></test-tag> value, everything works too. image

I tried also construction with isComponent defined but with the same result. Custom tags, specified in templates are not rendered on page load.

Looks like bug, or maybe I'm wrong somewhere and additional render calls required?

Thanks.

Answers (3)

artfFebruary 6, 20192 reactions

There are 2 issues:

  • You forgot to specify isComponent (used in the parsing process)
comps.addType('test-component-type', {
    isComponent: el => el.tagName === 'TEST-TAG',
    view: {
		// use onRender hook instead of render
        onRender() {
            const el = document.createElement("h1");
            el.innerText = 'TEST-COMPONENT OK';
            this.el.appendChild(el);
        }
    },
});
  • Currently, new component types are not working for the initial template, so the only way is to add them via plugins (I didn't find time to see why it's happening)

https://jsfiddle.net/m8hkuza3/

a-bashtannikFebruary 6, 20190 reactions

@artf , thank you for your answer, but I also

tried also construction with isComponent defined but with the same result.

whatever, I implemented this feature via plugins as you mentioned.

Have no idea why new component types don't work too, I will crate a PR if will figure out.

lock[bot]February 6, 20200 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.