Browse Source

[Beta] Fix double console logs in DEV (#5060)

main
dan 3 years ago
committed by GitHub
parent
commit
8fc62a5715
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      beta/src/components/MDX/Sandpack/Console.tsx

10
beta/src/components/MDX/Sandpack/Console.tsx

@ -93,7 +93,12 @@ export const SandpackConsole = () => {
const wrapperRef = React.useRef<HTMLDivElement>(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);

Loading…
Cancel
Save