"Empty" <ol> causing an error if it contains a non-element node
Note: This issue might relates to: tools/pagedjs#272
If a <ol>
element is "empty" (no elements inside) but contains at least one non-element node, it will cause PagedJs to crash.
Uncaught (in promise) TypeError: Cannot read property 'dataset' of null at Lists.afterPageLayout (paged.polyfill.js:30328)
For example, the following markup won't make PagedJs crash:
<ol></ol>
But this one will (as it contains a Text node (' '
)):
<ol>
</ol>
It seems like the problem comes from src/modules/paged-media/lists.js
, ln 18-19.
list.hasChildNodes()
checks for nodes inside the list, but it will also return true
if there are only non-element nodes, including white spaces:
Note: Whitespace inside a node is considered as text nodes, so if you leave any white space or line feeds inside an element, that element still has child nodes.
Which means that list.firstElementChild
may not exist, because it gets the first element node.
I'll make a merge request with a fix. I made a merge request (tools/pagedjs!152)