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
+
1
5
## 1.13.2 (06-09-2022)
2
6
3
7
* 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';
6
6
let loadedTimer ;
7
7
let pre = null ;
8
8
let preCursor ;
9
+ let prevCursorValue = '' ;
9
10
let initialPreDisplay = null ;
10
11
let preloader = null ;
11
12
let pushChunk = ( ) => { } ;
@@ -73,7 +74,14 @@ const flushData = (settings) => {
73
74
74
75
while ( true ) {
75
76
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 ;
77
85
78
86
if ( ! chunkNode ) {
79
87
if ( isFirstChunk && ( loaded || pre . nextSibling ) ) {
@@ -100,13 +108,20 @@ const flushData = (settings) => {
100
108
}
101
109
}
102
110
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
+ ) ;
104
118
} else {
105
119
// bailout: not a text node -> a complex markup is not a JSON
106
120
throw raiseBailout ( ) ;
107
121
}
108
122
109
123
preCursor = chunkNode ;
124
+ prevCursorValue = preCursor . nodeValue ;
110
125
}
111
126
} ;
112
127
You can’t perform that action at this time.
0 commit comments