Issue #6086Opened August 23, 2024by jdkcoder1 reactions

BUG: Cannot read properties of undefined (reading 'lastComponent') & resizable feature not work

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Edge v128

Reproducible demo links

  1. https://codesandbox.io/p/devbox/github/jdkcoder/cv-builder
  2. https://stackblitz.com/github/jdkcoder/cv-builder

Describe the bug

I'm using GrapesJS in Nuxt.js 3 project, the error Cannot read properties of undefined (reading 'lastComponent') shows after everytime I run clearAll() function in /components/common/LeftSidebar.vue

const { instance, reRender, outlineShown } = editorStore()

function clearAll() {
   if (confirm('Are you sure you want to clear the canvas?')) {
      instance.value.DomComponents.clear()
      localStorage.clear()
      reRender()
   }
}
<hr />

And here is how I was trying to implement "resize" feature at /stores/editor.store.js for "Text" block but it doesn't work & I don't know why :(

editor.DomComponents.addType('text', {
   model: {
      defaults: {
         resizable: {
            tl: 0, // Top left
            tc: 0, // Top center
            tr: 0, // Top right
            cl: 0, // Center left
            bl: 0, // Bottom left
         }
      }
   }
})

Answers (2)

artfAugust 25, 20241 reactions

You can skip removing the components (instance.value.Components.clear()) as you're destroying the editor anyway

if (confirm('Are you sure you want to clear the canvas?')) {
      localStorage.clear()
      reRender()
   }

This shouldn't generate any error

WilliamDASILVAAugust 24, 20240 reactions

@jdkcoder

By commenting the reRender function we don't have the issue anymore. The lastComponent error comes from the this.get('selected') in Editor being undefined at some point. And by checking the debugger, it indeed becomes undefined when the reRender is called because it re-initialize grapes.

For the resize, I don't see the issue with the Stackblitz example you gave. You should probably create a separate issue explaining more what's the behaviour you're having and what is expected I think.

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.