Repository navigation
fix(sdk): refetch first PLP page from page-load time, not build time - #3350
Conversation
useShouldFetchFirstPage previously used generatedBuildTime as the
reference for the 5-minute refetch window. For static PLP pages served
hours or days after build, the build-time check is always true on the
first client-side render, so the hook would refetch on every initial
navigation — defeating the cache injected by SSR.
Switch to a per-mount pageLoadTime ref (set on first render via
useRef(Date.now())) and only refetch once 5 minutes have elapsed since
the user actually opened the page. This matches the documented intent
("don't refetch immediately after SSR injects the cache") and removes
the dependency on the build timestamp from usePageProductsQuery.
Also reorders the hook body so useRef is called before any early return,
to comply with Rules of Hooks even when page !== 0.
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. |
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
WalkthroughThe PR shifts first-page product query refetch logic from server-side build time to client-side page-load timing, removing the ChangesClient-side page refresh timing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
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)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
Summary
useShouldFetchFirstPagepreviously usedgeneratedBuildTimeas the reference for the 5-minute refetch window. For static PLP pages served hours or days after the build, the build-time check is alwaystrueon the first client-side render, so the hook would refetch on every initial navigation — defeating the cache injected by SSR.This PR switches to a per-mount
pageLoadTimeref (set on first render viauseRef(Date.now())) and only refetches once 5 minutes have elapsed since the user actually opened the page. This matches the documented intent ("don't refetch immediately after SSR injects the cache") and removes the dependency on the build timestamp fromusePageProductsQuery.Also reorders the hook body so
useRefis called before thepage !== 0early return, complying with the Rules of Hooks.This is the third slice of #3345.
Behavior changes
useShouldFetchFirstPagechanges: thegeneratedBuildTimeparameter is removed. Only internal call site (usePageProductsQuery) is updated; the hook is not part of the documented SDK surface.Test plan
pnpm test --filter=@faststore/corepasses (existing tests foruseShouldFetchFirstPagemay need updates — flag if so).Made with Cursor
Summary by CodeRabbit