Skip to content

Commit

Permalink
NCL-8960 Fix error on Firefox when close WS client remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
DnsZhou committed Jan 6, 2025
1 parent 6a9e794 commit d95c4e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/components/LiveBuildLogPage/LiveBuildLogPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from 'react';
import { useCallback, useEffect, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';

import { buildLogMatchFiltersPrefix, buildLogPrefixFilters, useBifrostWebSocketEffect } from 'hooks/useBifrostWebSocketEffect';
Expand Down Expand Up @@ -29,9 +29,12 @@ export const LiveBuildLogPage = () => {
[buildId]
);

if (!isBuilding) {
navigate(`/builds/${buildId}/build-log`, { replace: true });
}
useEffect(() => {
// Move navigate function call into useEffect to make navigation occurs after the component has rendered
if (!isBuilding) {
navigate(`/builds/${buildId}/build-log`, { replace: true });
}
}, [isBuilding, navigate, buildId]);

useBifrostWebSocketEffect(
useCallback(
Expand Down
10 changes: 9 additions & 1 deletion src/services/webSocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export const createWebSocketClient = (url: string) => {
});
};

webSocket.onclose = (event: CloseEvent) => {
if (event.code === 1000) {
console.log(`WebSocket closed normally: Code ${event.code}, Reason: ${event.reason}`);
} else {
console.log(`WebSocket closed unexpectedly: Code ${event.code}`);
}
};

return {
/**
* Add WebSocket message listener.
Expand Down Expand Up @@ -91,7 +99,7 @@ export const createWebSocketClient = (url: string) => {
* Close the WebSocket connection.
*/
close: () => {
webSocket.close();
webSocket.close(1000, 'Client closed connection');
},
};
};
Expand Down

0 comments on commit d95c4e3

Please sign in to comment.