Skip to content

draftToHtml crashes with empty line from state #79

@flaviolivolsi

Description

@flaviolivolsi

An empty line inserted from the editor results in a crash of the application.

Example DraftJS content state:

{
    "blocks": [
      {
        "data": [
          
        ],
        "depth": 0,
        "entityRanges": [
          
        ],
        "inlineStyleRanges": [
          
        ],
        "key": "8r1pn",
        "text": "Header",
        "type": "header-two"
      },
      {
        "data": [
          
        ],
        "depth": 0,
        "entityRanges": [
          
        ],
        "inlineStyleRanges": [
          {
            "length": 3,
            "offset": 5,
            "style": "BOLD"
          }
        ],
        "key": "o7di",
        "text": "Test",
        "type": "unstyled"
      },
      {
        "data": [
          
        ],
        "depth": 0,
        "entityRanges": [
          
        ],
        "inlineStyleRanges": [
          
        ],
        "key": "fjqu1",
        "text": null,
        "type": "unstyled"
      }
    ],
    "entityMap": [
      
    ]
  }

draftToHtml function with this state yields this error:

Uncaught TypeError: Cannot read property 'length' of null
    at getSections (draftjs-to-html.js:158)
    at getBlockInnerMarkup (draftjs-to-html.js:569)
    at getBlockMarkup (draftjs-to-html.js:610)
    at draftjs-to-html.js:703
    at Array.forEach (<anonymous>)
    at draftToHtml (draftjs-to-html.js:692)
    at index.js:14
    at commitHookEffectListMount (react-dom.development.js:19764)
    at commitPassiveHookEffects (react-dom.development.js:19802)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at flushPassiveEffectsImpl (react-dom.development.js:22884)
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11061)
    at flushPassiveEffects (react-dom.development.js:22851)
    at react-dom.development.js:22730
    at workLoop (scheduler.development.js:597)
    at flushWork (scheduler.development.js:552)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:164)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions