99import { formatStatsMessages } from '../helpers/format' ;
1010import { logger } from '../logger' ;
1111import type { DevConfig , InternalContext , Rspack } from '../types' ;
12- import { reportRuntimeError } from './browserLogs' ;
12+ import { formatBrowserErrorLog } from './browserLogs' ;
1313import { genOverlayHTML } from './overlay' ;
1414
1515interface ExtWebSocket extends Ws {
@@ -86,6 +86,8 @@ export class SocketServer {
8686
8787 private getOutputFileSystem : ( ) => Rspack . OutputFileSystem ;
8888
89+ private reportedBrowserLogs : Set < string > = new Set ( ) ;
90+
8991 constructor (
9092 context : InternalContext ,
9193 options : DevConfig ,
@@ -184,8 +186,9 @@ export class SocketServer {
184186 } ) ;
185187 }
186188
187- public updateStats ( stats : Rspack . Stats , token : string ) : void {
189+ public onBuildDone ( stats : Rspack . Stats , token : string ) : void {
188190 this . stats [ token ] = stats ;
191+ this . reportedBrowserLogs . clear ( ) ;
189192
190193 if ( ! this . socketsMap . size ) {
191194 return ;
@@ -244,6 +247,7 @@ export class SocketServer {
244247 this . stats = { } ;
245248 this . initialChunks = { } ;
246249 this . socketsMap . clear ( ) ;
250+ this . reportedBrowserLogs . clear ( ) ;
247251
248252 return new Promise < void > ( ( resolve , reject ) => {
249253 this . wsServer . close ( ( err ) => {
@@ -264,7 +268,7 @@ export class SocketServer {
264268 socket . isAlive = true ;
265269 } ) ;
266270
267- socket . on ( 'message' , ( data ) => {
271+ socket . on ( 'message' , async ( data ) => {
268272 try {
269273 const message : ClientMessage = JSON . parse (
270274 // eslint-disable-next-line @typescript-eslint/no-base-to-string
@@ -278,7 +282,16 @@ export class SocketServer {
278282 // Do not report browser error when build failed
279283 ! this . context . buildState . hasErrors
280284 ) {
281- reportRuntimeError ( message , this . context , this . getOutputFileSystem ( ) ) ;
285+ const log = await formatBrowserErrorLog (
286+ message ,
287+ this . context ,
288+ this . getOutputFileSystem ( ) ,
289+ ) ;
290+
291+ if ( ! this . reportedBrowserLogs . has ( log ) ) {
292+ this . reportedBrowserLogs . add ( log ) ;
293+ logger . error ( log ) ;
294+ }
282295 }
283296 } catch { }
284297 } ) ;
0 commit comments