From 8fc62a5715f5f81a24b852514d3e13547779a012 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 14 Sep 2022 03:17:25 +0100 Subject: [PATCH] [Beta] Fix double console logs in DEV (#5060) --- beta/src/components/MDX/Sandpack/Console.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/beta/src/components/MDX/Sandpack/Console.tsx b/beta/src/components/MDX/Sandpack/Console.tsx index 2105e1fa..27b28e48 100644 --- a/beta/src/components/MDX/Sandpack/Console.tsx +++ b/beta/src/components/MDX/Sandpack/Console.tsx @@ -93,7 +93,12 @@ export const SandpackConsole = () => { const wrapperRef = React.useRef(null); React.useEffect(() => { + let isActive = true; const unsubscribe = listen((message) => { + if (!isActive) { + console.warn('Received an unexpected log from Sandpack.'); + return; + } if ( (message.type === 'start' && message.firstLoad) || message.type === 'refresh' @@ -117,7 +122,10 @@ export const SandpackConsole = () => { } }); - return unsubscribe; + return () => { + unsubscribe(); + isActive = false; + }; }, [listen]); const [isExpanded, setIsExpanded] = React.useState(true);