Skip to content

Commit

Permalink
fix(devtools-shared): delay unestablished ws connections from closing
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir committed May 8, 2024
1 parent 97f245f commit 9d9f375
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/devtools-shared/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ export const DevToolsContextProvider: React.FC<Props> = ({
return () => {
unsubscribe();

wsInstance.close(1000, window.location.origin);
// In strict mode, the WebSocket instance might not be connected yet
// so we need to wait for it to connect before closing it
// otherwise it will log an unnecessary error in the console
if (wsInstance.readyState === WebSocket.CONNECTING) {
wsInstance.addEventListener("open", () => {
wsInstance.close(1000, window.location.origin);
});
} else {
wsInstance.close(1000, window.location.origin);
}
};
}, []);

Expand Down

0 comments on commit 9d9f375

Please sign in to comment.