Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] codex-tolltip is not destroyed when EditorJS's destroy() #1475

Open
hata6502 opened this issue Dec 13, 2020 · 0 comments
Open

[Bug] codex-tolltip is not destroyed when EditorJS's destroy() #1475

hata6502 opened this issue Dec 13, 2020 · 0 comments
Labels

Comments

@hata6502
Copy link
Contributor

Describe a bug.
codex-tolltips are not destroyed when EditorJS's destroy().
So ToolTip's DOMs are leaked when create and destory EditorJS many times.

Steps to reproduce:

  1. Save the following HTML file as example/example-dev.html.
<!--
 Use this page for debugging purposes.

 Editor Tools are loaded as git-submodules.
 You can pull modules by running `yarn pull_tools` and start experimenting.
 -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Editor.js 🤩🧦🤨 example</title>
    <link
      href="https://fonts.googleapis.com/css?family=PT+Mono"
      rel="stylesheet"
    />
    <link href="assets/demo.css" rel="stylesheet" />
    <script src="assets/json-preview.js"></script>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
    />
  </head>
  <body>
    <div class="ce-example">
      <div class="ce-example__header">
        <a class="ce-example__header-logo" href="https://codex.so/editor"
          >Editor.js 🤩🧦🤨</a
        >

        <div class="ce-example__header-menu">
          <a href="https://github.com/editor-js" target="_blank">Plugins</a>
          <a href="https://editorjs.io/usage" target="_blank">Usage</a>
          <a href="https://editorjs.io/configuration" target="_blank"
            >Configuration</a
          >
          <a href="https://editorjs.io/creating-a-block-tool" target="_blank"
            >API</a
          >
        </div>
      </div>
      <div class="ce-example__content _ce-example__content--small">
        <div id="editorjs"></div>
        <div id="hint" style="text-align: center">
          No submodules found. Run
          <code class="inline-code">yarn pull_tools</code>
        </div>
        <div class="ce-example__button" id="saveButton">editor.save()</div>
        <div class="ce-example__statusbar">
          Readonly:
          <b id="readonly-state"> Off </b>
          <div class="ce-example__statusbar-button" id="toggleReadOnlyButton">
            toggle
          </div>
        </div>
      </div>
      <div class="ce-example__output">
        <pre class="ce-example__output-content" id="output"></pre>

        <div class="ce-example__output-footer">
          <a href="https://codex.so" style="font-weight: bold">Made by CodeX</a>
        </div>
      </div>
    </div>

    <!-- Load Tools -->
    <!--
   You can upload Tools to your project's directory and use as in example below.

   Also you can load each Tool from CDN or use NPM/Yarn packages.

   Read more in Tool's README file. For example:
   https://github.com/editor-js/header#installation
   -->
    <script
      src="./tools/header/dist/bundle.js"
      onload="document.getElementById('hint').hidden = true"
    ></script>
    <!-- Header -->
    <script src="./tools/simple-image/dist/bundle.js"></script>
    <!-- Image -->
    <script src="./tools/delimiter/dist/bundle.js"></script>
    <!-- Delimiter -->
    <script src="./tools/list/dist/bundle.js"></script>
    <!-- List -->
    <script src="./tools/checklist/dist/bundle.js"></script>
    <!-- Checklist -->
    <script src="./tools/quote/dist/bundle.js"></script>
    <!-- Quote -->
    <script src="./tools/code/dist/bundle.js"></script>
    <!-- Code -->
    <script src="./tools/embed/dist/bundle.js"></script>
    <!-- Embed -->
    <script src="./tools/table/dist/bundle.js"></script>
    <!-- Table -->
    <script src="./tools/link/dist/bundle.js"></script>
    <!-- Link -->
    <script src="./tools/raw/dist/bundle.js"></script>
    <!-- Raw -->
    <script src="./tools/warning/dist/bundle.js"></script>
    <!-- Warning -->

    <script src="./tools/marker/dist/bundle.js"></script>
    <!-- Marker -->
    <script src="./tools/inline-code/dist/bundle.js"></script>
    <!-- Inline Code -->

    <!-- Load Editor.js's Core -->
    <script src="../dist/editor.js"></script>

    <!-- Initialization -->
    <script>
      /**
       * To initialize the Editor, create a new instance with configuration object
       * @see docs/installation.md for mode details
       */
      setInterval(() => {
        var editor = new EditorJS({
          /**
           * Enable/Disable the read only mode
           */
          readOnly: false,

          /**
           * Wrapper of Editor
           */
          holder: "editorjs",

          /**
           * Common Inline Toolbar settings
           * - if true (or not specified), the order from 'tool' property will be used
           * - if an array of tool names, this order will be used
           */
          // inlineToolbar: ['link', 'marker', 'bold', 'italic'],
          // inlineToolbar: true,

          /**
           * Tools list
           */
          tools: {
            /**
             * Each Tool is a Plugin. Pass them via 'class' option with necessary settings {@link docs/tools.md}
             */
            header: {
              class: Header,
              inlineToolbar: ["marker", "link"],
              config: {
                placeholder: "Header",
              },
              shortcut: "CMD+SHIFT+H",
            },

            /**
             * Or pass class directly without any configuration
             */
            image: SimpleImage,

            list: {
              class: List,
              inlineToolbar: true,
              shortcut: "CMD+SHIFT+L",
            },

            checklist: {
              class: Checklist,
              inlineToolbar: true,
            },

            quote: {
              class: Quote,
              inlineToolbar: true,
              config: {
                quotePlaceholder: "Enter a quote",
                captionPlaceholder: "Quote's author",
              },
              shortcut: "CMD+SHIFT+O",
            },

            warning: Warning,

            marker: {
              class: Marker,
              shortcut: "CMD+SHIFT+M",
            },

            code: {
              class: CodeTool,
              shortcut: "CMD+SHIFT+C",
            },

            delimiter: Delimiter,

            inlineCode: {
              class: InlineCode,
              shortcut: "CMD+SHIFT+C",
            },

            linkTool: LinkTool,

            raw: RawTool,

            embed: Embed,

            table: {
              class: Table,
              inlineToolbar: true,
              shortcut: "CMD+ALT+T",
            },
          },

          /**
           * This Tool will be used as default
           */
          // defaultBlock: 'paragraph',

          /**
           * Initial Editor data
           */
          data: {
            blocks: [
              {
                type: "header",
                data: {
                  text: "Editor.js",
                  level: 2,
                },
              },
              {
                type: "paragraph",
                data: {
                  text:
                    "Hey. Meet the new Editor. On this page you can see it in action — try to edit this text. Source code of the page contains the example of connection and configuration.",
                },
              },
              {
                type: "header",
                data: {
                  text: "Key features",
                  level: 3,
                },
              },
              {
                type: "list",
                data: {
                  items: [
                    "It is a block-styled editor",
                    "It returns clean data output in JSON",
                    "Designed to be extendable and pluggable with a simple API",
                  ],
                  style: "unordered",
                },
              },
              {
                type: "header",
                data: {
                  text: "What does it mean «block-styled editor»",
                  level: 3,
                },
              },
              {
                type: "paragraph",
                data: {
                  text:
                    'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.',
                },
              },
              {
                type: "paragraph",
                data: {
                  text: `There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.`,
                },
              },
              {
                type: "header",
                data: {
                  text: "What does it mean clean data output",
                  level: 3,
                },
              },
              {
                type: "paragraph",
                data: {
                  text:
                    "Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below",
                },
              },
              {
                type: "paragraph",
                data: {
                  text: `Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.`,
                },
              },
              {
                type: "paragraph",
                data: {
                  text:
                    "Clean data is useful to sanitize, validate and process on the backend.",
                },
              },
              {
                type: "delimiter",
                data: {},
              },
              {
                type: "paragraph",
                data: {
                  text:
                    "We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make its core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏",
                },
              },
              {
                type: "image",
                data: {
                  url: "assets/codex2x.png",
                  caption: "",
                  stretched: false,
                  withBorder: true,
                  withBackground: false,
                },
              },
            ],
          },
          onReady: function () {
            saveButton.click();
          },
          onChange: function () {
            console.log("something changed");
          },
        });

        setTimeout(() => {
          editor.destroy();
        }, 1500);

        /**
         * Saving button
         */
        const saveButton = document.getElementById("saveButton");

        /**
         * Toggle read-only button
         */
        const toggleReadOnlyButton = document.getElementById(
          "toggleReadOnlyButton"
        );
        const readOnlyIndicator = document.getElementById("readonly-state");

        /**
         * Saving example
         */
        saveButton.addEventListener("click", function () {
          editor
            .save()
            .then((savedData) => {
              cPreview.show(savedData, document.getElementById("output"));
            })
            .catch((error) => {
              console.error("Saving error", error);
            });
        });

        /**
         * Toggle read-only example
         */
        toggleReadOnlyButton.addEventListener("click", async () => {
          const readOnlyState = await editor.readOnly.toggle();

          readOnlyIndicator.textContent = readOnlyState ? "On" : "Off";
        });
      }, 3000);
    </script>
  </body>
</html>
  1. access example/example-dev.html with browser.

  2. div.cts are created many times.

Expected behavior:
div.ct is destroyed when EditorJS's destroy().

Screenshots:
Screenshot from 2020-12-13 16-48-32

Device, Browser, OS: Ubuntu 20.04, Chrome

Editor.js version: 2.19.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant