diff --git a/packages/devtools-shared/src/context.tsx b/packages/devtools-shared/src/context.tsx index 8e3b14c01467..e98649f6dfdf 100644 --- a/packages/devtools-shared/src/context.tsx +++ b/packages/devtools-shared/src/context.tsx @@ -69,7 +69,16 @@ export const DevToolsContextProvider: React.FC = ({ 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); + } }; }, []);