draftToHtml crashes with empty line from state
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 325
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at getSections in draftjs-to-html.js:158 and trace the call from draftToHtml shown in the stack trace. Reproduce the failure with the supplied DraftJS content state, then verify that an unstyled block with null text no longer crashes draftToHtml and produces HTML.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100