feat: add page data preloading for navigation#83
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Singleton QueryClient with prefetchPageData for cache-aware preloading of /api/page responses. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fetchPageData now goes through react-query cache — prefetched data is served instantly without duplicate network requests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Global event delegation prefetches page data on mouseover/focusin. IntersectionObserver + MutationObserver handle viewport-visible and dynamically added links. Wired up in entry-client.tsx. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
API pages use /api/specs not /api/page, so prefetch requests for /apis/* paths were returning errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds TanStack React Query to Chronicle to enable intelligent page-data prefetching based on user interactions (hover, focus, viewport intersection) and consolidates caching logic. A shared ChangesReact Query Prefetch Implementation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/chronicle/src/lib/page-context.tsx (1)
16-16: ⚡ Quick winReuse the shared page-data query-key helper to avoid key drift.
fetchPageDatarebuilds the key inline while prefetching usespageDataQueryKey(...). Keeping a single key derivation path avoids silent prefetch cache misses later.Suggested refactor
-import { queryClient } from '`@/lib/preload`'; +import { pageDataQueryKey, queryClient } from '`@/lib/preload`'; @@ - return queryClient.fetchQuery({ - queryKey: ['pageData', key], + const pathname = `/${slug.join('/')}`; + return queryClient.fetchQuery({ + queryKey: pageDataQueryKey(pathname), queryFn: async () => {Also applies to: 118-122
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/chronicle/src/lib/page-context.tsx` at line 16, fetchPageData is constructing the page-data query key inline whereas prefetching uses the shared pageDataQueryKey(...) helper, causing possible cache misses; update fetchPageData to import and call pageDataQueryKey(...) instead of rebuilding the key, and use that same key when calling queryClient.fetchQuery/fetchInfiniteQuery so both producers/consumers use the identical key derivation (apply the same change for the other occurrence around lines 118-122). Ensure you replace any inline array/object key construction in fetchPageData with a single call to pageDataQueryKey(...) and pass that result to queryClient operations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/chronicle/src/components/PrefetchProvider.tsx`:
- Around line 4-5: The prefetch logic is using raw getAttribute('href') which
can yield relative URLs or include query/hash and cause wrong slugs; update
isInternalLink and the anchor handling in PrefetchProvider to resolve each href
against location.href via new URL(href, location.href), ensure the URL.origin
=== location.origin (to keep same-origin), then use url.pathname (normalized,
without query/hash) as the prefetch key/route to check/prefetch; replace any
direct uses of the raw href (from getAttribute('href')) with this normalized
pathname in functions such as isInternalLink and the anchor prefetch handlers so
caching and /api/page requests target the canonical path.
---
Nitpick comments:
In `@packages/chronicle/src/lib/page-context.tsx`:
- Line 16: fetchPageData is constructing the page-data query key inline whereas
prefetching uses the shared pageDataQueryKey(...) helper, causing possible cache
misses; update fetchPageData to import and call pageDataQueryKey(...) instead of
rebuilding the key, and use that same key when calling
queryClient.fetchQuery/fetchInfiniteQuery so both producers/consumers use the
identical key derivation (apply the same change for the other occurrence around
lines 118-122). Ensure you replace any inline array/object key construction in
fetchPageData with a single call to pageDataQueryKey(...) and pass that result
to queryClient operations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5459522d-065b-4cb2-aa08-d106a90795fa
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
packages/chronicle/package.jsonpackages/chronicle/src/components/PrefetchProvider.tsxpackages/chronicle/src/lib/page-context.tsxpackages/chronicle/src/lib/preload.tspackages/chronicle/src/server/entry-client.tsx
Raw getAttribute('href') can include hash fragments, query strings,
or relative paths that leak into the slug and cause bad API requests.
Resolve via new URL(href, location.href) and use pathname only.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ClientProvider QueryClientProvider stays in entry-client.tsx at app root. PrefetchProvider moved to src/components/ui/ to match project structure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prefetching page data only relevant for docs content pages, not API pages or landing page. Move from app root to DocsLayout which wraps sidebar + content area. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
@tanstack/react-queryfor cache-aware data fetching/api/pagedata on hover, focus, and viewport intersection via global event delegationPageProvider.fetchPageDatanow usesqueryClient.fetchQuery— prefetched data served instantly/apis/*routes (use different endpoint)Test plan
🤖 Generated with Claude Code