From 2b2013be7b3643edfac707a9196d3fc91a1e8502 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 19 May 2026 10:14:54 +0530 Subject: [PATCH 1/3] fix: skip prefetching for sidebar top links Add data-no-prefetch attribute check in PrefetchProvider to skip links that shouldn't be prefetched. Apply to content and API top links in sidebar which are index routes, not doc pages. Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/chronicle/src/components/ui/PrefetchProvider.tsx | 6 +++--- packages/chronicle/src/themes/default/Layout.tsx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/chronicle/src/components/ui/PrefetchProvider.tsx b/packages/chronicle/src/components/ui/PrefetchProvider.tsx index 17c6a2a..48022d8 100644 --- a/packages/chronicle/src/components/ui/PrefetchProvider.tsx +++ b/packages/chronicle/src/components/ui/PrefetchProvider.tsx @@ -16,14 +16,14 @@ export function PrefetchProvider({ children }: { children: React.ReactNode }) { useEffect(() => { const handleMouseOver = (e: MouseEvent) => { const anchor = (e.target as HTMLElement).closest?.('a[href]'); - if (!anchor) return; + if (!anchor || anchor.hasAttribute('data-no-prefetch')) return; const pathname = resolvePathname(anchor.getAttribute('href')); if (pathname) prefetchPageData(pathname); }; const handleFocusIn = (e: FocusEvent) => { const anchor = (e.target as HTMLElement).closest?.('a[href]'); - if (!anchor) return; + if (!anchor || anchor.hasAttribute('data-no-prefetch')) return; const pathname = resolvePathname(anchor.getAttribute('href')); if (pathname) prefetchPageData(pathname); }; @@ -45,7 +45,7 @@ export function PrefetchProvider({ children }: { children: React.ReactNode }) { ); const observeLinks = () => { - document.querySelectorAll('a[href]:not([data-prefetch-observed])').forEach((link) => { + document.querySelectorAll('a[href]:not([data-prefetch-observed]):not([data-no-prefetch])').forEach((link) => { const pathname = resolvePathname(link.getAttribute('href')); if (pathname) { link.setAttribute('data-prefetch-observed', ''); diff --git a/packages/chronicle/src/themes/default/Layout.tsx b/packages/chronicle/src/themes/default/Layout.tsx index 5a7ddc4..faa9a51 100644 --- a/packages/chronicle/src/themes/default/Layout.tsx +++ b/packages/chronicle/src/themes/default/Layout.tsx @@ -138,7 +138,7 @@ export function Layout({ )} classNames={{ root: styles.topLinkItem, text: styles.topLinkText }} - render={} + render={} > {entry.label} @@ -154,7 +154,7 @@ export function Layout({ )} classNames={{ root: styles.topLinkItem, text: styles.topLinkText }} - render={} + render={} > {api.name} API From 3e1082259fb7602bf52f2b372f086cd6642191fa Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 19 May 2026 10:16:20 +0530 Subject: [PATCH 2/3] refactor: extract data-no-prefetch attr name to constant Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/chronicle/src/components/ui/PrefetchProvider.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/chronicle/src/components/ui/PrefetchProvider.tsx b/packages/chronicle/src/components/ui/PrefetchProvider.tsx index 48022d8..21ced7b 100644 --- a/packages/chronicle/src/components/ui/PrefetchProvider.tsx +++ b/packages/chronicle/src/components/ui/PrefetchProvider.tsx @@ -1,6 +1,8 @@ import { useEffect } from 'react'; import { prefetchPageData } from '@/lib/preload'; +const NO_PREFETCH_ATTR = 'data-no-prefetch'; + function resolvePathname(href: string | null): string | null { if (!href) return null; try { @@ -16,14 +18,14 @@ export function PrefetchProvider({ children }: { children: React.ReactNode }) { useEffect(() => { const handleMouseOver = (e: MouseEvent) => { const anchor = (e.target as HTMLElement).closest?.('a[href]'); - if (!anchor || anchor.hasAttribute('data-no-prefetch')) return; + if (!anchor || anchor.hasAttribute(NO_PREFETCH_ATTR)) return; const pathname = resolvePathname(anchor.getAttribute('href')); if (pathname) prefetchPageData(pathname); }; const handleFocusIn = (e: FocusEvent) => { const anchor = (e.target as HTMLElement).closest?.('a[href]'); - if (!anchor || anchor.hasAttribute('data-no-prefetch')) return; + if (!anchor || anchor.hasAttribute(NO_PREFETCH_ATTR)) return; const pathname = resolvePathname(anchor.getAttribute('href')); if (pathname) prefetchPageData(pathname); }; @@ -45,7 +47,7 @@ export function PrefetchProvider({ children }: { children: React.ReactNode }) { ); const observeLinks = () => { - document.querySelectorAll('a[href]:not([data-prefetch-observed]):not([data-no-prefetch])').forEach((link) => { + document.querySelectorAll('a[href]:not([data-prefetch-observed]):not([${NO_PREFETCH_ATTR}])').forEach((link) => { const pathname = resolvePathname(link.getAttribute('href')); if (pathname) { link.setAttribute('data-prefetch-observed', ''); From 548c9a47486feb32950341ccd637a5fd509331c8 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 19 May 2026 10:32:42 +0530 Subject: [PATCH 3/3] fix: use template literal for querySelector interpolation Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/chronicle/src/components/ui/PrefetchProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/chronicle/src/components/ui/PrefetchProvider.tsx b/packages/chronicle/src/components/ui/PrefetchProvider.tsx index 21ced7b..480c758 100644 --- a/packages/chronicle/src/components/ui/PrefetchProvider.tsx +++ b/packages/chronicle/src/components/ui/PrefetchProvider.tsx @@ -47,7 +47,7 @@ export function PrefetchProvider({ children }: { children: React.ReactNode }) { ); const observeLinks = () => { - document.querySelectorAll('a[href]:not([data-prefetch-observed]):not([${NO_PREFETCH_ATTR}])').forEach((link) => { + document.querySelectorAll(`a[href]:not([data-prefetch-observed]):not([${NO_PREFETCH_ATTR}])`).forEach((link) => { const pathname = resolvePathname(link.getAttribute('href')); if (pathname) { link.setAttribute('data-prefetch-observed', '');