Skip to content

Cache main navigation categories tree#100

Merged
damianlegawiec merged 1 commit into
mainfrom
fix/cache-categories-nav
Apr 1, 2026
Merged

Cache main navigation categories tree#100
damianlegawiec merged 1 commit into
mainfrom
fix/cache-categories-nav

Conversation

@damianlegawiec
Copy link
Copy Markdown
Member

@damianlegawiec damianlegawiec commented Apr 1, 2026

Summary by CodeRabbit

  • Chores
    • Optimized category data caching to improve application performance.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
storefront Ready Ready Preview, Comment Apr 1, 2026 7:59pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 1, 2026

Walkthrough

A caching helper function cachedListCategories was introduced in the categories module with Next.js cache directives. The existing getCategories function was updated to route list-fetching through this new helper instead of calling the API directly.

Changes

Cohort / File(s) Summary
Category Data Caching
src/lib/data/categories.ts
Introduced internal helper cachedListCategories with Next.js cache directives ("use cache", cacheLife("hours"), cacheTag("categories")). Updated getCategories to use this helper for list-fetching operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A helper so fine, with caching so sweet,
Categories now cached, the optimization's neat!
Next.js directives, wrapping with care,
Performance improved, data to spare! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Cache main navigation categories tree' accurately describes the main change: introducing caching for categories via a new cachedListCategories helper that applies Next.js cache directives to the category list fetching logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cache-categories-nav

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/lib/data/categories.ts (1)

7-15: Add explicit return type and consider cache invalidation strategy.

  1. Per coding guidelines, functions should have explicit return types:
Suggested fix
+import type { Category, PaginatedResponse } from "@spree/sdk";
+
 async function cachedListCategories(
   params: CategoryListParams | undefined,
   options: { locale?: string; country?: string },
-) {
+): Promise<PaginatedResponse<Category>> {
   "use cache";
  1. The codebase pattern (see cart.ts, addresses.ts, checkout.ts) uses updateTag() for cache invalidation after mutations. There's no corresponding updateTag("categories") call anywhere. If categories are modified through admin flows, you'll need a revalidation mechanism (e.g., webhook endpoint, on-demand ISR, or time-based expiry alone).

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/data/categories.ts` around lines 7 - 15, Add an explicit return type
to cachedListCategories (e.g., Promise<Category[]> or the appropriate API
response type returned by getClient().categories.list) and ensure the categories
cache is invalidated when mutations occur: keep cacheTag("categories") in
cachedListCategories but add updateTag("categories") calls in any
category-changing mutation handlers (or implement a webhook/on-demand
revalidation endpoint) so admin changes trigger cache revalidation; reference
cachedListCategories and the cacheTag("categories")/updateTag("categories")
symbols when applying the changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lib/data/categories.ts`:
- Around line 7-15: Add an explicit return type to cachedListCategories (e.g.,
Promise<Category[]> or the appropriate API response type returned by
getClient().categories.list) and ensure the categories cache is invalidated when
mutations occur: keep cacheTag("categories") in cachedListCategories but add
updateTag("categories") calls in any category-changing mutation handlers (or
implement a webhook/on-demand revalidation endpoint) so admin changes trigger
cache revalidation; reference cachedListCategories and the
cacheTag("categories")/updateTag("categories") symbols when applying the
changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 648632a8-e10c-4e32-b637-714cdd2f021e

📥 Commits

Reviewing files that changed from the base of the PR and between 64296ce and 9ff3f32.

📒 Files selected for processing (1)
  • src/lib/data/categories.ts

@damianlegawiec damianlegawiec merged commit ddde355 into main Apr 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant