Repository navigation
perf(plp): prioritize first product image as LCP (VTE-14) - #3348
Conversation
PageSpeed Insights consistently identifies the first product card image as the LCP element on PLP, even when a Hero section is present. Make the browser fetch it earlier and prioritize its decoding/painting. - ProductListingPage: render <link rel="preload" as="image" fetchPriority="high"> in <Head> for the first product image, using faststoreLoader with width=320 so the URL exactly matches the <img> srcset selection at Lighthouse mobile (412px viewport, DPR=2, 30vw). - ProductGrid: set fetchPriority="high" on the first card image, and switch eager loading from idx === 0 to idx < 4 so the first row above the fold is not blocked by lazy loading. - ProductCard: forward fetchPriority from imgProps to the underlying Image component. Co-authored-by: Cursor <[email protected]>
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Re-applies the changes that were lost when the original commit ended up empty due to a husky pre-commit hook interaction. - ProductListingPage: render <link rel="preload" as="image" fetchPriority="high"> in <Head> for the first product image, using faststoreLoader with width=320 so the URL exactly matches the <img> srcset selection at Lighthouse mobile (412px viewport, DPR=2, 30vw). - ProductGrid: set fetchPriority="high" on the first card image, and switch eager loading from idx === 0 to idx < 4 so the first row above the fold is not blocked by lazy loading. - ProductCard: forward fetchPriority from imgProps to the underlying Image component. Co-authored-by: Cursor <[email protected]>
WalkthroughThis PR optimizes image loading performance across product listing pages by introducing conditional ChangesImage Loading Priority Optimization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/core/src/components/product/ProductGrid/ProductGrid.tsx`:
- Around line 192-194: The ProductGrid component currently treats firstPage as
optional which can disable the LCP fetchPriority optimization when callers
accidentally pass undefined; update ProductGrid so firstPage is always
defined—either make the firstPage prop required in the ProductGrid props
interface (remove optional marker) or give it a safe default (default firstPage
= 0 in the ProductGrid function signature) and then use that defined value in
the fetchPriority check (the comparison using firstPage inside ProductGrid where
loading/fetchPriority are set). Also audit call sites (ProductGalleryPage,
ProductGallery, useSearch usage) to ensure they still pass or rely on the
enforced/ defaulted firstPage.
🪄 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: d604c919-abbb-466e-a327-34141a189155
📒 Files selected for processing (3)
packages/core/src/components/product/ProductCard/ProductCard.tsxpackages/core/src/components/product/ProductGrid/ProductGrid.tsxpackages/core/src/components/templates/ProductListingPage/ProductListingPage.tsx
| loading: idx < 4 ? 'eager' : 'lazy', | ||
| fetchPriority: | ||
| idx === 0 && page === firstPage ? 'high' : undefined, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for ProductGrid usage to verify firstPage is provided
rg -nP --type=tsx --type=ts -C3 '<ProductGrid\b' -g '!ProductGrid.tsx'Repository: vtex/faststore
Length of output: 86
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Inspect ProductGrid.tsx around the optional `firstPage` typing and the usage near lines 192-194
FILE='packages/core/src/components/product/ProductGrid/ProductGrid.tsx'
echo "=== Context: $FILE (lines 1-80) ==="
sed -n '1,120p' "$FILE" | cat -n
echo "=== Context: $FILE (lines 160-240) ==="
sed -n '160,240p' "$FILE" | cat -n
# 2) Find ProductGrid usages excluding its own file
echo "=== Searching for ProductGrid call sites ==="
rg -n --glob '!**/ProductGrid.tsx' --glob '**/*.{ts,tsx,js,jsx}' -C3 'ProductGrid\b' packages/core/src packages/components/src 2>/dev/null || true
rg -n --glob '!**/ProductGrid.tsx' --glob '**/*.{ts,tsx,js,jsx}' -C3 'ProductGrid\b' packages 2>/dev/null || trueRepository: vtex/faststore
Length of output: 23663
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the known call site around where ProductGrid is rendered
FILE='packages/core/src/components/ui/ProductGallery/ProductGalleryPage.tsx'
echo "=== Context: $FILE (ProductGrid usage) ==="
rg -n '<ProductGrid\b' "$FILE" -n
sed -n '35,110p' "$FILE" | cat -n
# Search for any ProductGrid JSX usage and whether firstPage is passed
echo "=== Search: <ProductGrid ... firstPage=... ==="
rg -n '<ProductGrid\b[^>]*\bfirstPage=' packages/core/src packages/components/src packages 2>/dev/null || true
echo "=== Search: <ProductGrid\b' call sites (excluding export/type noise) ==="
rg -n '<ProductGrid\b' packages/core/src packages/components/src packages -S --glob '!**/*.d.ts' 2>/dev/null || true
echo "=== Search: firstPage usage anywhere ==="
rg -n '\bfirstPage\b' packages/core/src packages/components/src packages 2>/dev/null || trueRepository: vtex/faststore
Length of output: 3349
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE='packages/core/src/components/ui/ProductGallery/ProductGallery.tsx'
echo "=== Context: $FILE (around firstPage={pages[0]}) ==="
sed -n '280,360p' "$FILE" | cat -n
echo "=== Search: how `pages` is computed ==="
rg -n '\bconst pages\b|pages\s*=' "$FILE"
# show the definition of `pages` plus nearby lines
rg -n '\bpages\b' "$FILE" -n | head -n 50Repository: vtex/faststore
Length of output: 3973
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE='packages/core/src/components/ui/ProductGallery/ProductGallery.tsx'
echo "=== Search for `pages` definition in $FILE ==="
rg -n --no-heading '\bconst\s+pages\b|\bpages\s*=' "$FILE"
# Show the most relevant nearby blocks for the `pages` definition
# (First match only, to keep output small)
LINE=$(rg -n --no-heading '\bconst\s+pages\b|\bpages\s*=' "$FILE" | head -n 1 | cut -d: -f1)
echo "=== Showing around line $LINE ==="
sed -n "$((LINE-20)),$((LINE+40))p" "$FILE" | cat -n
echo "=== Find where `pages[0]` is used ==="
rg -n 'firstPage=\{pages\[0\]\}' "$FILE" -nRepository: vtex/faststore
Length of output: 220
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE='packages/core/src/components/ui/ProductGallery/ProductGallery.tsx'
echo "=== First 60 matches of `pages` in $FILE ==="
rg -n '\bpages\b' "$FILE" | head -n 60
echo
echo "=== Around the line that uses firstPage={pages[0]} ==="
FIRSTPAGE_LINE=$(rg -n 'firstPage=\{pages\[0\]\}' "$FILE" | head -n 1 | cut -d: -f1 || true)
echo "firstPage line: ${FIRSTPAGE_LINE:-<not found>}"
if [ -n "${FIRSTPAGE_LINE:-}" ]; then
sed -n "$((FIRSTPAGE_LINE-40)),$((FIRSTPAGE_LINE+40))p" "$FILE" | cat -n
fi
echo
echo "=== Around the line(s) with pages.map((page) => ...) ==="
MAP_LINE=$(rg -n 'pages\.map\(\(page\)\s*=>' "$FILE" | head -n 1 | cut -d: -f1 || true)
echo "map line: ${MAP_LINE:-<not found>}"
if [ -n "${MAP_LINE:-}" ]; then
sed -n "$((MAP_LINE-40)),$((MAP_LINE+60))p" "$FILE" | cat -n
fiRepository: vtex/faststore
Length of output: 8855
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect where `pages` comes from in ProductGallery.tsx
FILE='packages/core/src/components/ui/ProductGallery/ProductGallery.tsx'
echo "=== Context around `const { pages, ... } = useSearch()` in $FILE ==="
sed -n '110,170p' "$FILE" | cat -n
# Find definition/import of useSearch in this file
echo
echo "=== Import/definition of useSearch in $FILE ==="
rg -n 'useSearch' "$FILE"
# Resolve where useSearch is implemented and inspect its return type
# (Search for `function useSearch` or `export const useSearch` across core)
echo
echo "=== Finding useSearch implementation ==="
rg -n --type=ts --type=tsx 'useSearch\s*=\s*|function\s+useSearch|export\s+function\s+useSearch' packages/core/src packages -S --glob '!**/*.d.ts' 2>/dev/null || trueRepository: vtex/faststore
Length of output: 2940
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Find where useSearch is implemented in this repo (it's imported from `@faststore/sdk`)
echo "=== Searching for useSearch implementation ==="
rg -n --type=ts --type=tsx 'useSearch\s*=\s*|function\s+useSearch|export\s+function\s+useSearch' packages 2>/dev/null || true
echo
echo "=== Searching for 'pages' return shape from useSearch ==="
rg -n --type=ts --type=tsx '\bpages\b' packages -S 2>/dev/null | head -n 50Repository: vtex/faststore
Length of output: 164
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Quick inventory of packages
echo "=== packages/ ==="
ls -1 packages | head -n 200
# Find the workspace package that corresponds to `@faststore/sdk`
echo
echo "=== Search package.json for `@faststore/sdk` ==="
rg -n '"name"\s*:\s*"`@faststore/sdk`"' -S packages 2>/dev/null || true
# Try locating useSearch type/definition inside the repo (if `@faststore/sdk` is vendored here)
echo
echo "=== Search for 'useSearch' in packages (excluding dist/build) ==="
rg -n --type=ts --type=tsx --type=dts --type=js --type=mjs --type=cjs 'useSearch' packages -S 2>/dev/null || true
# Also search for the literal import source '`@faststore/sdk`'
echo
echo "=== Search for import { useSearch } from '`@faststore/sdk`' ==="
rg -n --type=ts --type=tsx "from '`@faststore/sdk`'" packages -S 2>/dev/null || trueRepository: vtex/faststore
Length of output: 374
🏁 Script executed:
#!/bin/bash
set -euo pipefail
SDK_DIR='packages/sdk'
echo "=== Search for useSearch implementation in $SDK_DIR ==="
rg -n --type=ts --type=tsx --type=d.ts --type=cts --type=mts 'useSearch' "$SDK_DIR" -S
echo
echo "=== Search for 'pages' usage in $SDK_DIR ==="
rg -n --type=ts --type=tsx 'pages' "$SDK_DIR" -S | head -n 80
echo
echo "=== Narrow: search for where pages is returned from useSearch ==="
rg -n --type=ts --type=tsx 'return\s+\{[^}]*pages|pages\s*:' "$SDK_DIR" -S || trueRepository: vtex/faststore
Length of output: 164
🏁 Script executed:
#!/bin/bash
set -euo pipefail
SDK_DIR='packages/sdk'
echo "=== Search for useSearch implementation (ts/tsx only) in $SDK_DIR ==="
rg -n --glob '*.{ts,tsx}' 'useSearch' "$SDK_DIR" -S || true
echo
echo "=== Search for `pages` mentions in $SDK_DIR ==="
rg -n --glob '*.{ts,tsx}' '\bpages\b' "$SDK_DIR" -S | head -n 120 || true
echo
echo "=== Narrow: search for pages in useSearch-related code ==="
rg -n --glob '*.{ts,tsx}' -S 'useSearch.*pages|pages.*useSearch|function\s+useSearch|export\s+function\s+useSearch|const\s+useSearch' "$SDK_DIR" || trueRepository: vtex/faststore
Length of output: 6124
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect useSearch + the global search state that provides `pages`
SDK_FILE_STATE='packages/sdk/src/search/globalState/useSearchState.ts'
SDK_FILE_USESEARCH='packages/sdk/src/search/useSearch.ts'
SDK_FILE_PAGINATION='packages/sdk/src/search/usePagination.ts'
echo "=== useSearch.ts ==="
sed -n '1,120p' "$SDK_FILE_USESEARCH" | cat -n
echo
echo "=== useSearchState.ts (pages type + default init) ==="
# show around the interface/type and initial values
sed -n '1,220p' "$SDK_FILE_STATE" | cat -n
echo
echo "=== usePagination.ts (assumptions about pages non-empty) ==="
sed -n '1,120p' "$SDK_FILE_PAGINATION" | cat -nRepository: vtex/faststore
Length of output: 6751
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n --glob '!**/ProductGrid.tsx' '<ProductGrid\b' packages -S --glob '*.{ts,tsx,js,jsx}' 2>/dev/null || trueRepository: vtex/faststore
Length of output: 150
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect tests that assert default pages initialization in sdk search Provider
rg -n --glob '*.{ts,tsx}' 'pages\.toEqual\(\[0\]|\bpages\b.*toEqual\(' packages/sdk/test/search/Provider.test.tsx
echo
rg -n --glob '*.{ts,tsx}' 'resetInfiniteScroll|start\(|initialize\(|pages:' packages/sdk/test/search/Provider.test.tsx | head -n 80
# Show the sections around where pages are asserted
rg -n --glob '*.{ts,tsx}' 'expect\(result\.current\.pages\)' packages/sdk/test/search/Provider.test.tsxRepository: vtex/faststore
Length of output: 213
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect Provider.test.tsx around the assertions
FILE='packages/sdk/test/search/Provider.test.tsx'
echo "=== Context around pages expectations in $FILE ==="
sed -n '360,460p' "$FILE" | cat -n
echo
echo "=== Context around where pages are initialized/modified in $FILE ==="
# show early initialization section too
sed -n '1,120p' "$FILE" | cat -n
echo
echo "=== Inspect packages/sdk/src/search/Provider.tsx for pages initialization ==="
PROV='packages/sdk/src/search/Provider.tsx'
sed -n '1,120p' "$PROV" | cat -n
sed -n '120,260p' "$PROV" | cat -nRepository: vtex/faststore
Length of output: 9737
ProductGrid firstPage handling: callers pass it; keep it robust
All current ProductGrid call sites pass a firstPage value: ProductGalleryPage requires firstPage: number and forwards it to ProductGrid, and ProductGallery supplies it as pages[0] from useSearch. In @faststore/sdk, pages is a number[] initialized to [0] when session storage is missing, and pagination updates always keep it non-empty—so the page === firstPage LCP fetchPriority="high" optimization shouldn’t silently disable in normal flows.
Edge case: if session storage contains an empty pages array ([]), pages[0] becomes undefined and the optimization drops; consider making firstPage required in ProductGrid props or defaulting firstPage to 0.
🤖 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/core/src/components/product/ProductGrid/ProductGrid.tsx` around
lines 192 - 194, The ProductGrid component currently treats firstPage as
optional which can disable the LCP fetchPriority optimization when callers
accidentally pass undefined; update ProductGrid so firstPage is always
defined—either make the firstPage prop required in the ProductGrid props
interface (remove optional marker) or give it a safe default (default firstPage
= 0 in the ProductGrid function signature) and then use that defined value in
the fetchPriority check (the comparison using firstPage inside ProductGrid where
loading/fetchPriority are set). Also audit call sites (ProductGalleryPage,
ProductGallery, useSearch usage) to ensure they still pass or rely on the
enforced/ defaulted firstPage.

0 New Issues
0 Fixed Issues
0 Accepted Issues
Summary
Improves PLP LCP by making the browser fetch and prioritize the first product card image earlier.
<link rel="preload" as="image" fetchPriority="high">in<Head>for the first product image. The preload URL is generated byfaststoreLoaderwithwidth=320so it exactly matches the<img>srcset selection at Lighthouse mobile (412px viewport, DPR≈2,sizes="30vw"→ 247px → next srcset step = 320). This avoids a double fetch.fetchPriority: 'high'on the first card image, and switch eager loading fromidx === 0toidx < 4so the first visible row is not blocked by lazy loading.fetchPriorityfromimgPropsto the underlyingImagecomponent.This is the first slice of #3345.
Context
PageSpeed Insights identifies the first product card image as the LCP element on PLP even when a Hero section is present — the hero renders at a smaller visual area than the first product card on mobile.
Test plan
request not usedwarning in DevTools).server.search.products.edges[0]is missing (no preload link rendered).pnpm test --filter=@faststore/corepasses.Made with Cursor
Summary by CodeRabbit