Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty block not being added to blocks[]

See original GitHub issue

When you hit Enter, a new and empty paragraph block is added on page. However, this does not get added to the blocks[] array.

The problem with this is that the getCurrentBlockIndex() API method queries elements from the DOM, so it’s now de-synced from the actual data - you can’t use it as a source of truth anymore. In a Vue.js context, where data is your source of truth, this is problematic.

In my case, this happens:

  1. I have a paragraph block on page - this would be at index 0 if queried for
  2. hit Enter, new paragraph block created on page, at index 1 (but not in data)
  3. insert a new block at the end with the API (triggered with click on a button). This block is at index 2 when queried for, but at index 1 in my blocks[] data, because nothing was added at step 2…

Any ideas on how to overcome this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

ngmiduccommented, Oct 30, 2021

Hi @cossssmin ,

Empty blocks are not added to saved data because of validation provided by Tools. Default Editor.js paragraph doesn’t validate empty strings. You can fork it, change validate method, and provide at tools object of configuration.

Thanks for the solution. If someone wants to a React Overwrite. I paste it here, if maybe someone looks for that.

const NewParagraphTool = (function (original) {
  function Paragraph() {
    original.apply(this, arguments) 
    this.validate = function (savedData) {
      // if (savedData.text.trim() === "" && !this._preserveBlank) {
      //   return false
      // }

      return true
  Paragraph.prototype = original.prototype 
  Paragraph.prototype.constructor = Paragraph 
  return Paragraph
cossssmincommented, Dec 7, 2019

Thanks @gohabereg, but I don’t want to have to maintain a fork - all I’d want is for the getCurrentBlockIndex() to work reliably 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why aren't more empty blocks mined? - Bitcoin Stack Exchange
There is some kind of relationship between empty blocks and difficulty increase/decrease that I have not been able to formulate properly.
Read more >
Adding blocks – Forums
Click on the Block Inserter + icon to the right of an empty block. This will open a modal window with a list...
Read more >
Database, not including empty blocks, is substantially larger ...
Database, not including empty blocks, is substantially larger than the actual data size at a point in time. Many areas have database blocks...
Read more >
no-empty-block - Dart Code Metrics
Disallows empty blocks except catch clause block. Blocks with a todo comment inside are not considered empty. Empty blocks are often indicators of...
Read more >
Menu block renders when tree is empty as of 8.x-1.8 [regression]
Removing the access check in #3216265: Module causes double rendering of blocks just to check access now means that empty menu blocks are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found