File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1+ ## next
2+
3+ * Fixed JSON parsing error issue when data loading from a slow responding server (#82 )
4+
15## 1.13.2 (06-09-2022)
26
37* Fixed copy to clipboard in FireFox
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ let loaded = document.readyState === 'complete';
66let loadedTimer ;
77let pre = null ;
88let preCursor ;
9+ let prevCursorValue = '' ;
910let initialPreDisplay = null ;
1011let preloader = null ;
1112let pushChunk = ( ) => { } ;
@@ -73,7 +74,14 @@ const flushData = (settings) => {
7374
7475 while ( true ) {
7576 const isFirstChunk = preCursor === undefined ;
76- const chunkNode = isFirstChunk ? pre . firstChild : preCursor . nextSibling ;
77+ const chunkNode = isFirstChunk
78+ ? pre . firstChild
79+ // In some cases a browser appends new content to an existing text node
80+ // instead of creating new one. In this case, we are using the same text node
81+ // as on previous iteration and slice appended content as a chunk content.
82+ : preCursor . nodeValue !== prevCursorValue
83+ ? preCursor
84+ : preCursor . nextSibling ;
7785
7886 if ( ! chunkNode ) {
7987 if ( isFirstChunk && ( loaded || pre . nextSibling ) ) {
@@ -100,13 +108,20 @@ const flushData = (settings) => {
100108 }
101109 }
102110
103- pushChunk ( chunkNode . nodeValue ) ;
111+ pushChunk (
112+ chunkNode === preCursor
113+ // slice a new content from a chunk node in case a content
114+ // was appended to an existing text node
115+ ? chunkNode . nodeValue . slice ( prevCursorValue . length )
116+ : chunkNode . nodeValue
117+ ) ;
104118 } else {
105119 // bailout: not a text node -> a complex markup is not a JSON
106120 throw raiseBailout ( ) ;
107121 }
108122
109123 preCursor = chunkNode ;
124+ prevCursorValue = preCursor . nodeValue ;
110125 }
111126} ;
112127
You can’t perform that action at this time.
0 commit comments