diff --git a/packages/ui/src/components/Highlight/Highlight.tsx b/packages/ui/src/components/Highlight/Highlight.tsx index fcb0384e4..fff9602bd 100644 --- a/packages/ui/src/components/Highlight/Highlight.tsx +++ b/packages/ui/src/components/Highlight/Highlight.tsx @@ -13,16 +13,17 @@ interface HighlightProps { export const Highlight: React.FC = ({ language, text }) => { const [code, setCode] = useState(''); - const textToCode = async () => { - setCode(await asyncHighlight(text as string, language)); - }; - - useEffect(() => { - textToCode(); - }, []); - useEffect(() => { - textToCode(); + let unmount = false; + asyncHighlight(text as string, language).then((newCode) => { + if (!unmount) { + setCode(newCode); + } + }); + + return () => { + unmount = true; + }; }, [language, text]); const handleCopyClick = () => { @@ -35,10 +36,7 @@ export const Highlight: React.FC = ({ language, text }) => { -