Skip to content

Commit 3e249bd

Browse files
STRMLsophiebits
authored andcommitted
Check nodeType before attempting to highlight. (facebook#361)
Since React v15 uses comment nodes to split text (rather than <span>s), this fixes a crashing bug.
1 parent 7efca36 commit 3e249bd

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

frontend/Highlighter/Overlay.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class Overlay {
8484
}
8585

8686
inspect(node: DOMNode, name?: ?string) {
87+
// We can't get the size of text nodes or comment nodes. React as of v15
88+
// heavily uses comment nodes to delimit text.
89+
if (node.nodeType !== Node.ELEMENT_NODE) {
90+
return;
91+
}
8792
var box = node.getBoundingClientRect();
8893
var dims = getElementDimensions(node);
8994

frontend/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type DOMNode = {
2828
innerHTML: string,
2929
innerText: string,
3030
nodeName: string,
31+
nodeType: number,
3132
offsetHeight: number,
3233
offsetLeft: number,
3334
offsetParent: ?DOMNode,

0 commit comments

Comments
 (0)