Issue #1501💬 AnsweredOpened October 11, 2018by mararn16180 reactions

Issue with editor.destroy() and reinitialization

快速解答by mararn1618

Hey @artf , are you planning to fix this in future releases? I belive this is relevant to many other issues people encounter, especially when using JS/SPA frameworks.

Read full answer below ↓

Question

With GrapesJS 0.14.33 editor.destroy() was introduced (https://github.com/artf/grapesjs/commit/52f8bdf2e894de536d44c1699c1e18bbaf52488f), so that it is possible to initialize, destroy and reinitialize an editor.

Problem

After initializing, destroying, re-initializing, I am however experiencing exceptions when editing text-blocks with the default RTE. Today's destroy() eventually forgets to tear down s.th., so that it is possible to provoke the following:

Uncaught TypeError: Cannot read property 'body' of null
    at Object.getBody (grapes.js:24607)
    at Object.getWrapperEl (grapes.js:24616)
    at child.getCanvasWrapper (grapes.js:26883)
    at child.initialize (grapes.js:26842)
    at child.Backbone.View (grapes.js:5596)
    at child [as constructor] (grapes.js:6256)
    at new child (grapes.js:6256)
    at Object.get (grapes.js:26519)
    at Object.method (grapes.js:38111)
    at dispatch (grapes.js:19528)

or:

Uncaught TypeError: Cannot read property 'hasFocus' of null

Demo

Please find this fiddle for 0.14.33 including reproduction steps: https://jsfiddle.net/srkm18yu/

Related PRs and Issues

In my opinion PR #920 has already fixed part of this problem, but was not sufficient.

Other people have experienced the same issue in the past, especially when they are building SPAs, e.g. with Angular, since an SPA will reinitialize GrapesJS everytime the user navigates to page using a GrapesJS editor e.g. #1288.

Answers (2)

mararn1618October 25, 2018

Hey @artf , are you planning to fix this in future releases? I belive this is relevant to many other issues people encounter, especially when using JS/SPA frameworks.

lock[bot]November 22, 2019

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

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.