Fixed SSR and SEO of Product Details - #80
Conversation
WalkthroughThe PR refactors product page data fetching by removing the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 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 (1)
src/app/[country]/[locale]/(storefront)/products/[slug]/ProductDetails.tsx (1)
47-50: Consider adding a guard to prevent duplicate view tracking.The
useEffectfires wheneverproductorcurrencychanges. If theproductobject reference is recreated (e.g., during a client-side navigation or hydration mismatch), this could trigger duplicateview_itemanalytics events.Consider tracking only on initial mount or using a ref to prevent duplicate fires:
♻️ Optional: Guard against duplicate tracking
+import { useEffect, useMemo, useRef, useState } from "react"; // Track product view (analytics - client-only side effect) +const trackedProductRef = useRef<string | null>(null); useEffect(() => { + if (trackedProductRef.current === product.id) return; + trackedProductRef.current = product.id; trackViewItem(product, currency); -}, [product, currency]); +}, [product, currency]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app/`[country]/[locale]/(storefront)/products/[slug]/ProductDetails.tsx around lines 47 - 50, The useEffect calling trackViewItem(product, currency) can fire multiple times when product or currency references change; update the logic in the ProductDetails component to only fire once per product view (e.g., on initial mount or when product.id changes) by adding a guard using a ref (or a Set) to remember tracked product IDs and skip subsequent calls; make the guard check the unique product identifier before invoking trackViewItem so repeated re-renders or recreated product objects won't emit duplicate view_item events.
🤖 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)/products/[slug]/ProductDetails.tsx:
- Around line 47-50: The useEffect calling trackViewItem(product, currency) can
fire multiple times when product or currency references change; update the logic
in the ProductDetails component to only fire once per product view (e.g., on
initial mount or when product.id changes) by adding a guard using a ref (or a
Set) to remember tracked product IDs and skip subsequent calls; make the guard
check the unique product identifier before invoking trackViewItem so repeated
re-renders or recreated product objects won't emit duplicate view_item events.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 31339cec-5d41-44c4-8dc7-7a5bcca2dbb2
📒 Files selected for processing (5)
src/app/[country]/[locale]/(storefront)/products/[slug]/ProductDetails.tsxsrc/app/[country]/[locale]/(storefront)/products/[slug]/ProductDetailsWrapper.tsxsrc/app/[country]/[locale]/(storefront)/products/[slug]/page.tsxsrc/lib/data/cached.tssrc/lib/metadata/product.ts
💤 Files with no reviewable changes (1)
- src/app/[country]/[locale]/(storefront)/products/[slug]/ProductDetailsWrapper.tsx
Summary by CodeRabbit
New Features
Bug Fixes
Refactor