File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,12 +99,33 @@ function classify(line) {
9999 return 'level-info' ;
100100}
101101
102- function appendLine ( text ) {
103- const div = document . createElement ( 'div' ) ;
104- div . className = 'log-line ' + classify ( text ) ;
105- div . textContent = text ;
106- log . appendChild ( div ) ;
102+ const lineQueue = [ ] ;
103+ let flushScheduled = false ;
104+
105+ function flushQueue ( ) {
106+ if ( lineQueue . length === 0 ) {
107+ flushScheduled = false ;
108+ return ;
109+ }
110+ const fragment = document . createDocumentFragment ( ) ;
111+ while ( lineQueue . length > 0 ) {
112+ const text = lineQueue . shift ( ) ;
113+ const div = document . createElement ( 'div' ) ;
114+ div . className = 'log-line ' + classify ( text ) ;
115+ div . textContent = text ;
116+ fragment . appendChild ( div ) ;
117+ }
118+ log . appendChild ( fragment ) ;
107119 if ( autoScroll ) log . scrollTop = log . scrollHeight ;
120+ flushScheduled = false ;
121+ }
122+
123+ function appendLine ( text ) {
124+ lineQueue . push ( text ) ;
125+ if ( ! flushScheduled ) {
126+ flushScheduled = true ;
127+ requestAnimationFrame ( flushQueue ) ;
128+ }
108129}
109130
110131const es = new EventSource ( '/stream' ) ;
You can’t perform that action at this time.
0 commit comments