kommitters / editorjs-toggle-block

Toggle block tool for EditorJS
https://www.npmjs.com/package/editorjs-toggle-block
MIT License
43 stars 20 forks source link

Editor js freezes when trying to render toggle block #155

Closed megazoll closed 2 years ago

megazoll commented 2 years ago

Precheck

Description

When adding toggle block to editor, saving data and then trying to render data back, editor js breaks down. Looks like an infinite loop somewhere in plugin.

Environment

Current behavior

https://codepen.io/megazoll/pen/VwxzMQx

Expected behavior

Editorjs should render toggle block

untilhamza commented 2 years ago

Cause of this issue

 if (this.readOnly) {
      const redactor = document.getElementsByClassName('codex-editor__redactor')[0];
      const { children } = redactor;
      const { length } = children;

      for (let i = 0; i < length; i += 1) {
        const blockCover = children[i].firstChild;
        const blockContainer = blockCover.firstChild;
        const { id } = blockContainer;

        if (id === this.wrapper.id) {
          toggleRoot = i;
          break;
        }
      }
    } else {
      const toggle = this.wrapper.children[1];
      let currentBlock = {};

      while (currentBlock[1] !== toggle) {
        // 🚨🚨***** INFO: this is an infinite loop ***** 🚨🚨
        toggleRoot = this.api.blocks.getCurrentBlockIndex();
        const block = this.api.blocks.getBlockByIndex(toggleRoot);
        const { holder } = block;
        const blockCover = holder.firstChild;
        const blockContent = blockCover.firstChild;
        currentBlock = blockContent.children;

        this.api.caret.setToNextBlock('end', 0);
      }
    }
yimin087 commented 2 years ago

I also met

miguelnietoa commented 2 years ago

Thank you all for reporting the bug, we will prioritize it!

miguelnietoa commented 2 years ago

Hi there! This bug has been solved in the v0.3.1 😅

untilhamza commented 2 years ago

Hi there! This bug has been solved in the v0.3.1 😅

Thank you so much 😇

yimin087 commented 2 years ago

Thank you so much