File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,21 @@ const WorkerFormatters = {
7575 } ,
7676 json : ( content : Buffer ) => {
7777 const asString = content . toString ( 'utf8' ) ;
78- return formatJson ( asString , { formatRecords : false } ) ;
78+
79+ // Do simplify parse + stringify where possible for speed - it's up to 1000x faster.
80+ // We fall back to the relaxed formatJson() where that fails, which is slower but
81+ // always comes up with something reasonable - unless it's very large, in which
82+ // case we give up rather than hanging the UI:
83+ try {
84+ return JSON . stringify ( JSON . parse ( asString ) , null , 2 ) ;
85+ } catch ( e ) {
86+ if ( content . byteLength <= 5_000_000 ) {
87+ return formatJson ( asString , { formatRecords : false } ) ;
88+ } else {
89+ // Large non-parseable content - we fall back to the raw string
90+ return asString ;
91+ }
92+ }
7993 } ,
8094 'json-records' : ( content : Buffer ) => {
8195 const asString = content . toString ( 'utf8' ) ;
You can’t perform that action at this time.
0 commit comments