fix(techdocs): avoid rerender when clicking on anchor links in same page (#26938)
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs': patch
|
||||
---
|
||||
|
||||
Avoid page re-rendering when clicking on anchor links in the same documentation page.
|
||||
@@ -208,7 +208,18 @@ export const useTechDocsReaderDom = (
|
||||
if (modifierActive) {
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
navigate(url);
|
||||
// If it's in a different page, we navigate to it
|
||||
if (window.location.pathname !== parsedUrl.pathname) {
|
||||
navigate(url);
|
||||
} else {
|
||||
// If it's in the same page we avoid using navigate that causes
|
||||
// the page to rerender.
|
||||
window.history.pushState(
|
||||
null,
|
||||
document.title,
|
||||
parsedUrl.hash,
|
||||
);
|
||||
}
|
||||
// Scroll to hash if it's on the current page
|
||||
transformedElement
|
||||
?.querySelector(`[id="${parsedUrl.hash.slice(1)}"]`)
|
||||
|
||||
Reference in New Issue
Block a user