perf: remove navbar remount key & add passive scroll/touch listeners

- Remove key={String(open)} from MobileNav container to prevent
  unnecessary full DOM remounts on every menu toggle (fixes #1098)
  The animate prop already handles border-radius transitions via
  Framer Motion so the key prop was redundant
- Add { passive: true } to all scroll and touch event listeners
  (fixes #1053)
  window.addEventListener('scroll') in Navbar and MobileNav
  document.addEventListener('touchstart') in click-outside handler
  window.addEventListener('scroll', true) in onboarding-tour (uses
  capture + passive since handlers only read geometry, no preventDefault)
This commit is contained in:
mac-agent 2026-04-05 07:05:03 -04:00
parent 6f6be19f9d
commit cbe463ae90
2 changed files with 3 additions and 4 deletions

View file

@ -32,7 +32,7 @@ export const Navbar = ({ scrolledBgClassName }: NavbarProps = {}) => {
};
handleScroll();
window.addEventListener("scroll", handleScroll);
window.addEventListener("scroll", handleScroll, { passive: true });
return () => window.removeEventListener("scroll", handleScroll);
}, []);
@ -132,7 +132,7 @@ const MobileNav = ({ navItems, isScrolled, scrolledBgClassName }: any) => {
};
document.addEventListener("mousedown", handleClickOutside);
document.addEventListener("touchstart", handleClickOutside);
document.addEventListener("touchstart", handleClickOutside, { passive: true });
return () => {
document.removeEventListener("mousedown", handleClickOutside);
document.removeEventListener("touchstart", handleClickOutside);
@ -143,7 +143,6 @@ const MobileNav = ({ navItems, isScrolled, scrolledBgClassName }: any) => {
<motion.div
ref={navRef}
animate={{ borderRadius: open ? "4px" : "2rem" }}
key={String(open)}
className={cn(
"relative mx-auto flex w-full max-w-[calc(100vw-2rem)] flex-col items-center justify-between px-4 py-2 lg:hidden transition-all duration-300",
isScrolled

View file

@ -598,7 +598,7 @@ export function OnboardingTour() {
};
window.addEventListener("resize", handleUpdate);
window.addEventListener("scroll", handleUpdate, true);
window.addEventListener("scroll", handleUpdate, { capture: true, passive: true });
return () => {
window.removeEventListener("resize", handleUpdate);