Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-donuts-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@node-core/doc-kit': patch
---

Sync the URL hash when following same-page search hits
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const followSearchHit = event => {
return;
}

const target = new URL(event.currentTarget.href);
const { href } = event.currentTarget;

event.preventDefault();

Expand All @@ -30,18 +30,16 @@ const followSearchHit = event => {
new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })
);

requestAnimationFrame(() => {
if (target.pathname !== window.location.pathname) {
window.location.href = target.href;
return;
}

requestAnimationFrame(() =>
document
.getElementById(decodeURIComponent(target.hash.slice(1)))
?.scrollIntoView()
);
});
// A plain `location.href` assignment covers both cases: same-page hits
// become a native fragment navigation (hash, scroll and history entry
// included), cross-page hits simply load the target page. The nested
// `requestAnimationFrame` waits for the modal to actually close —
// navigating while it is still open suppresses the fragment scroll.
requestAnimationFrame(() =>
requestAnimationFrame(() => {
window.location.href = href;
})
);
};

/**
Expand Down
Loading