dispatch icon indicating copy to clipboard operation
dispatch copied to clipboard

Manager cannot load article with empty heading

Open psiemens opened this issue 3 years ago • 1 comments

What behaviour were you expecting?

The Dispatch admin panel should not fail to load articles with empty headings.

What actually happened?

The Dispatch admin panel crashes when loading an article with an empty heading.

This error occurs primarily on the article listing page, given that the listing includes an article with an empty heading.

Steps to reproduce

  1. Create a new article
  2. In the article, create a new line with several characters. Select the characters and format them as heading.
  3. Delete the characters but keep the empty line
  4. Click "Update"
  5. Navigate back to the article listing page. The page should be blank
  6. Observe the error in the JS console

What was your environment like?

Google Chrome Version 86.0.4240.111, macOS

Do you have any logs?

The error occurs on this un-minified line.

Screen Shot 2020-10-25 at 12 48 01 AM

The above line maps to this function in the source code: https://github.com/ubyssey/dispatch/blob/6612ebe58c51332bc148bae362255835ba0ac5fc/dispatch/static/manager/src/js/vendor/dispatch-editor/helpers/convertJSON.js#L118-L126

The Chrome Debugger shows the value of the block parameter:

Screen Shot 2020-10-25 at 12 56 08 AM

block is a single element taken directly from the content field of an article API response. In this case, the original JSON value is:

{"type":"header","data":{"content":"","size":"h2"}}

psiemens avatar Nov 02 '20 07:11 psiemens

This crashed the manager in production for the ubyssey.ca deployment of Dispatch. After an article was saved with an empty heading, the article listing page crashed for any listing that included the "bad" article.

To immediately fix the problem, I manually updated the bad article to remove the empty heading block.

psiemens avatar Nov 02 '20 08:11 psiemens