Issue #4906Opened February 6, 2023by panditlakshya0 reactions

BUG: Grapesjs fails to recognize component types when setting innerHTML through script.

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

chrome v108.0.5359.98

Reproducible demo link

https://codesandbox.io/s/grapes-js-template-literal-forked-6kgvrb?file=/src/App.js

Describe the bug

I'm trying to create a custom component that recognizes inner html component types after injecting html code through script.

How to reproduce the bug?

  1. Just inject the html through script
const el = this;
el.innerHTML = `<div data-gjs-resizable="true" data-gjs-layerable="true" data-gjs-draggable="true" data-gjs-selectable="true" data-gjs-hoverable="true">
<img data-gjs-resizable="true" data-gjs-layerable="true" data-gjs-draggable="true" data-gjs-selectable="true" data-gjs-hoverable="true" src="" alt="">
<h5 data-gjs-resizable="true" data-gjs-layerable="true" data-gjs-draggable="true" data-gjs-selectable="true" data-gjs-hoverable="true">Lakshya</h5>
<h6 data-gjs-resizable="true" data-gjs-layerable="true" data-gjs-draggable="true" data-gjs-selectable="true" data-gjs-hoverable="true">Artist</h6>
</div>`;

What is the expected behavior? Canvas should be able to recognize component types like text, image, etc after injecting code.

What is the current behavior? Injected part is recognized as text component as whole.(Injected code may contain div element with image or text)

If is necessary to execute some code in order to reproduce the bug, paste it here below:

// your code here

Code of Conduct

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

Answers (1)

artfFebruary 7, 20230 reactions

Read carefully this guide, everything inside script is outside of the editor scope. You can update the component itself by using component.components method or specify the components: '<div ....' directly in definition.

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.