Only replace the shadow dom if the content is changed to avoid a flickering UI

Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
Dominik Henneke
2021-10-15 17:14:12 +02:00
parent 59e822b43c
commit cdf8ca6111
2 changed files with 14 additions and 2 deletions
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs': patch
---
Only replace the shadow dom if the content is changed to avoid a flickering UI.
@@ -397,6 +397,11 @@ const TheReader = ({
const dom = useTechDocsReaderDom();
const shadowDomRef = useRef<HTMLDivElement>(null);
const onReadyRef = useRef<() => void>(onReady);
useEffect(() => {
onReadyRef.current = onReady;
}, [onReady]);
useEffect(() => {
if (!dom || !shadowDomRef.current) return;
const shadowDiv = shadowDomRef.current;
@@ -406,8 +411,10 @@ const TheReader = ({
shadowRoot.removeChild(child),
);
shadowRoot.appendChild(dom);
onReady();
}, [dom, onReady]);
onReadyRef.current();
// this hook must ONLY be triggered by a changed dom
}, [dom]);
return (
<>