refs: https://bugzilla.mozilla.org/show_bug.cgi?id=1250972 Love me some decade old bugs.
This commit is contained in:
parent
c6db42dff0
commit
f1caef1058
|
|
@ -34,14 +34,21 @@ export function Nav({
|
||||||
rootMargin: "-10px",
|
rootMargin: "-10px",
|
||||||
threshold: 0.5, // Adjust the visibility threshold as needed
|
threshold: 0.5, // Adjust the visibility threshold as needed
|
||||||
};
|
};
|
||||||
|
let timeout: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
|
if (timeout) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
}
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
const target = entry.target.id as keyof (typeof translations.pl)["nav"]
|
const target = entry.target.id as keyof (typeof translations.pl)["nav"]
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
setActiveSection(target);
|
setActiveSection(target);
|
||||||
if (history.replaceState) {
|
if (window.location.hash !== `#${target}` && history.replaceState) {
|
||||||
history.replaceState(null, "", `#${target}`);
|
timeout = setTimeout(() => {
|
||||||
|
history.replaceState(null, "", `#${target}`)
|
||||||
|
}, 150)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue