GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.09k stars 4.02k forks source link

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

Closed jdkcoder closed 2 weeks ago

jdkcoder commented 2 weeks ago

GrapesJS version

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()
   }
}

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
         }
      }
   }
})
WilliamDASILVA commented 2 weeks ago

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

artf commented 2 weeks ago

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