fix: update marketplace stats fetch to include timestamp and adjust d…#359
fix: update marketplace stats fetch to include timestamp and adjust d…#359wolgwang1729 wants to merge 4 commits intoshopstr-eng:mainfrom
Conversation
|
@wolgwang1729 is attempting to deploy a commit to the shopstr-eng Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes inconsistent first-load homepage marketplace stats by making the stats request re-run when product event count changes and by avoiding stale cached responses.
Changes:
- Adds a cache-busting timestamp query param to the marketplace stats API fetch.
- Updates the stats-fetching
useEffectdependency to re-run whenproductEvents.lengthchanges.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pages/index.tsx
Outdated
|
|
||
| useEffect(() => { | ||
| fetch("/api/db/marketplace-stats") | ||
| fetch(`/api/db/marketplace-stats?t=${Date.now()}`) |
There was a problem hiding this comment.
Using Date.now() as a query param forces a unique URL on every request, which can defeat CDN/browser caching entirely and can also lead to cache/key cardinality growth in intermediaries (each timestamp is a distinct cache key). Prefer controlling freshness via HTTP caching semantics (e.g., server Cache-Control: no-store / no-cache or client fetch options like cache: 'no-store') or a bounded version token that changes only when underlying data changes.
| fetch(`/api/db/marketplace-stats?t=${Date.now()}`) | |
| fetch("/api/db/marketplace-stats", { cache: "no-store" }) |
pages/index.tsx
Outdated
| }) | ||
| .catch(() => {}); | ||
| }, []); | ||
| }, [productEventContext.productEvents.length]); |
There was a problem hiding this comment.
Depending on productEventContext.productEvents.length directly often trips the React Hooks exhaustive-deps rule (because productEventContext / productEvents are referenced but not listed). Also, if the array content changes without a length change, the effect won’t re-run. Consider deriving a stable dependency (e.g., a memoized productEventsLength), or include the referenced object/array in deps and compute length inside the effect to satisfy linting and ensure intended refresh behavior.
|
I was getting the following error, which is why I added safe JSON parsing Error TypeRuntime SyntaxError Error MessageUnexpected end of JSON input Code Frame376 | if (pubkeyProfilesToFetch.includes(event.pubkey)) {
Next.js version: 16.1.7 (Turbopack) |
81a4a94 to
2cc8c51
Compare
2cc8c51 to
c6505dd
Compare
c6505dd to
0984fc3
Compare
| content, | ||
| nip05Verified: false, | ||
| }; | ||
| if (content.nip05) { |
There was a problem hiding this comment.
Hi @arnavkirti, I rebased and resolved the conflicts in the branch. I kept the fetch-service.tschanges from PR #294, but I’d appreciate it if you could verify that the latest merge didn’t break any of the profile-handling behavior or the DB caching changes from your PR.
Description
This PR fixes the homepage stats first-load inconsistency in the Shopstr by the Numbers section (locally verified).
pages/index.tsxso it re-runs when product data length changes, instead of only once on initial mount.0or placeholders until manual refresh.Resolved or fixed issue
Fixes #358
Video
Screen.Recording.showing.the.fix.mp4
Affirmation