From e937ae7b1f9b9b8822a965e48046e568f75a33da Mon Sep 17 00:00:00 2001 From: Sydney Achinger <78113809+squid-ney@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:38:34 -0500 Subject: [PATCH] Fix unecessary re-rendering of site's index page. (#27505) Signed-off-by: Sydney Achinger --- .changeset/hungry-cats-juggle.md | 5 +++++ .../reader/components/TechDocsReaderPageContent/dom.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/hungry-cats-juggle.md diff --git a/.changeset/hungry-cats-juggle.md b/.changeset/hungry-cats-juggle.md new file mode 100644 index 0000000000..af52f9388f --- /dev/null +++ b/.changeset/hungry-cats-juggle.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs': patch +--- + +Fix an issue with index page of documentation site being re-rendered. diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx index 3656d22326..8d23ed7b8b 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx @@ -47,6 +47,7 @@ import { handleMetaRedirects, } from '../../transformers'; import { useNavigateUrl } from './useNavigateUrl'; +import { useParams } from 'react-router-dom'; const MOBILE_MEDIA_QUERY = 'screen and (max-width: 76.1875em)'; @@ -69,6 +70,7 @@ export const useTechDocsReaderDom = ( const scmIntegrationsApi = useApi(scmIntegrationsApiRef); const { state, path, content: rawPage } = useTechDocsReader(); + const { '*': currPath = '' } = useParams(); const [dom, setDom] = useState(null); const isStyleLoading = useShadowDomStylesLoading(dom); @@ -277,8 +279,8 @@ export const useTechDocsReaderDom = ( } // Skip this update if the location's path has changed but the state - // contains a page for another page that isn't loaded yet. - if (!window.location.pathname.endsWith(path)) { + // contains a page that isn't loaded yet. + if (currPath !== path) { return; } @@ -297,7 +299,7 @@ export const useTechDocsReaderDom = ( return () => { shouldReplaceContent = false; }; - }, [rawPage, path, preRender, postRender]); + }, [rawPage, currPath, path, preRender, postRender]); return dom; };