summernote: "TypeError: a is null" thrown only in FireFox

I get “TypeError: a is null” thrown only in FireFox.

It show this bit as causing the error:

...1?"&nbsp;":"<br>",G=function(a){return g(a)?a.nodeValue.length:a.childNodes.leng... ----------------------------------------------------------^

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 16 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I’m also getting this error, and it only occurs in Firefox. The page I’m working on is rather complicated, so I’m unable to isolate a test case. However, using the un-minified version, I was able to track down the error. The exact error message is actually “TypeError: node is null” and here’s the stack trace for version 0.8.1:

dom</nodeLength() - summernote.js:634 dom</isRightEdgeOf() - summernote.js:907 dom</isRightEdgePointOf() - summernote.js:933 range</WrappedRange/this.normalize/getVisiblePoint() - summernote.js:2472 range</WrappedRange/this.normalize() - summernote.js:2487 Editor/this.currentStyle() - summernote.js:3878 Context/this.invoke() - summernote.js:1711 Buttons/this.updateCurrentStyle() - summernote.js:5622 Context/this.invoke() - summernote.js:1711 Toolbar/this.initialize() - summernote.js:5757 Context/this.initializeModule() - summernote.js:1640 Context/this._initialize/<() - summernote.js:1570 forEach() - self-hosted:216 Context/this._initialize() - summernote.js:1569 Context/this.initialize() - summernote.js:1527 Context() - summernote.js:1715 .summernote/<() - summernote.js:1738

I did some digging and in the getVisiblePoint() function call, for some reason the block variable is null:

// point on block's edge
var block = dom.ancestor(point.node, dom.isBlock);

Later on, when the isRightEdgeOf() function is called, it traverses up the dom tree. But, when it reaches the top, node.parentNode is null and nodeLength(node.parentNode) throws the error message (because null has no childNodes). My (probably incorrect) work around was to simply add the following line to the nodeLength() function:

if (node === null) { return 0; }

Thanks @lesilent

I had the same problem in firefox and corrects the problem by following your tip follows the amendment

    var nodeLength = function (node) {
      if (node === null) {
        return 0;
      } else {
        if (isText(node)) {
          return node.nodeValue.length;
        }
        return node.childNodes.length;
      }
    };