@@ -396,7 +396,8 @@ export class WebSocketManager {
396396 }
397397
398398 if ( this . transitionChunkBuffer !== null ) {
399- throw new Error (
399+ this . transitionChunkBuffer = null ;
400+ this . logger . log (
400401 `Received unexpected ${ serverMessage . type } while buffering TransitionChunks` ,
401402 ) ;
402403 }
@@ -552,6 +553,7 @@ export class WebSocketManager {
552553 * closed socket is not accessible or used again after this method is called
553554 */
554555 private close ( ) : Promise < void > {
556+ this . transitionChunkBuffer = null ;
555557 switch ( this . socket . state ) {
556558 case "disconnected" :
557559 case "terminated" :
@@ -560,6 +562,10 @@ export class WebSocketManager {
560562 return Promise . resolve ( ) ;
561563 case "connecting" : {
562564 const ws = this . socket . ws ;
565+ // Messages can still be received after close but we're not interested.
566+ ws . onmessage = ( _message ) => {
567+ this . _logVerbose ( "Ignoring message received after close" ) ;
568+ } ;
563569 return new Promise ( ( r ) => {
564570 ws . onclose = ( ) => {
565571 this . _logVerbose ( "Closed after connecting" ) ;
@@ -574,6 +580,10 @@ export class WebSocketManager {
574580 case "ready" : {
575581 this . _logVerbose ( "ws.close called" ) ;
576582 const ws = this . socket . ws ;
583+ // Messages can still be received after close but we're not interested.
584+ ws . onmessage = ( _message ) => {
585+ this . _logVerbose ( "Ignoring message received after close" ) ;
586+ } ;
577587 const result : Promise < void > = new Promise ( ( r ) => {
578588 ws . onclose = ( ) => {
579589 r ( ) ;
0 commit comments