Add caching to category page#121
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (2)
src/app/[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsx (1)
12-16: Add an explicit return type onCategoryBanner.Line 12 should declare the return type instead of relying on inference.
As per coding guidelines: "Use strict TypeScript type checking. Always define explicit return types for functions, use 'satisfies' for type checking object literals, and avoid 'any' (use 'unknown' instead)."♻️ Proposed refactor
export async function CategoryBanner({ category, basePath, locale, -}: CategoryBannerProps) { +}: CategoryBannerProps): Promise<JSX.Element> {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app/`[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsx around lines 12 - 16, The CategoryBanner async component is missing an explicit return type; update the function signature for CategoryBanner to declare its return type (e.g., change to export async function CategoryBanner({ category, basePath, locale, }: CategoryBannerProps): Promise<JSX.Element> { … }) so the async React component returns a typed Promise<JSX.Element> and satisfies strict TypeScript checks.src/lib/data/categories.ts (1)
22-38: Add explicit return types tocachedGetCategoryandgetCategory.Line 22 and Line 33 currently rely on inference; please make return types explicit per repo TS rules.
As per coding guidelines: "Use strict TypeScript type checking. Always define explicit return types for functions, use 'satisfies' for type checking object literals, and avoid 'any' (use 'unknown' instead)."♻️ Proposed refactor
import type { CategoryListParams, ProductListParams } from "@spree/sdk"; import { cacheLife, cacheTag } from "next/cache"; import { getClient, getLocaleOptions } from "@/lib/spree"; +type GetCategoryResponse = Awaited< + ReturnType<ReturnType<typeof getClient>["categories"]["get"]> +>; + async function cachedListCategories( params: CategoryListParams | undefined, options: { locale?: string; country?: string }, ) { @@ async function cachedGetCategory( idOrPermalink: string, params: { expand?: string[] } | undefined, options: { locale?: string; country?: string }, -) { +): Promise<GetCategoryResponse> { "use cache: remote"; cacheLife("minutes"); cacheTag("category"); return getClient().categories.get(idOrPermalink, params, options); } @@ export async function getCategory( idOrPermalink: string, params?: { expand?: string[] }, -) { +): Promise<GetCategoryResponse> { const options = await getLocaleOptions(); return cachedGetCategory(idOrPermalink, params, options); }🤖 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 22 - 38, Both cachedGetCategory and getCategory lack explicit return types; add explicit Promise return types for each (matching whatever type getClient().categories.get returns) instead of relying on inference. Update cachedGetCategory to declare its return type as a Promise of the category response type used by the client (import or reference the client response type), and set getCategory to return the same explicit Promise type; if you prefer a type-safe alias, derive it from the client method (e.g., Awaited<ReturnType<typeof getClient().categories.get>>), and add any needed imports—do not use any/unknown as the final return type.
🤖 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/app/`[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsx:
- Around line 12-16: The CategoryBanner async component is missing an explicit
return type; update the function signature for CategoryBanner to declare its
return type (e.g., change to export async function CategoryBanner({ category,
basePath, locale, }: CategoryBannerProps): Promise<JSX.Element> { … }) so the
async React component returns a typed Promise<JSX.Element> and satisfies strict
TypeScript checks.
In `@src/lib/data/categories.ts`:
- Around line 22-38: Both cachedGetCategory and getCategory lack explicit return
types; add explicit Promise return types for each (matching whatever type
getClient().categories.get returns) instead of relying on inference. Update
cachedGetCategory to declare its return type as a Promise of the category
response type used by the client (import or reference the client response type),
and set getCategory to return the same explicit Promise type; if you prefer a
type-safe alias, derive it from the client method (e.g.,
Awaited<ReturnType<typeof getClient().categories.get>>), and add any needed
imports—do not use any/unknown as the final return type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 66e14cb6-fa75-4677-8373-ac97223af017
📒 Files selected for processing (3)
src/app/[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsxsrc/app/[country]/[locale]/(storefront)/c/[...permalink]/page.tsxsrc/lib/data/categories.ts
Summary by CodeRabbit
Performance
Refactor