Skip to content

fix: eliminate useSearchParams self-redirect loop on listing detail pages - #176

Merged
mxjxn merged 4 commits into
mainfrom
copilot/fix-nextjs-self-redirect-loop
Jun 26, 2026
Merged

fix: eliminate useSearchParams self-redirect loop on listing detail pages#176
mxjxn merged 4 commits into
mainfrom
copilot/fix-nextjs-self-redirect-loop

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

In Next.js 16, calling useSearchParams() inside a client component rendered within a <Suspense> boundary causes the RSC renderer to emit a 307 replace redirect to the same URL — an infinite loop that Next.js breaks by serving its 404 page. All /listing/[listingId] pages were blank as a result.

Changes

  • useAuctionDetail.ts: Removed useSearchParams() call. Hook now accepts referralAddress?: string | null as a prop instead of reading it from search params internally.

  • listing/[listingId]/AuctionDetailClient.tsx:

    • Removed top-level useSearchParams() (the chainId read was redundant — the server component already handles chainId redirects before the client renders)
    • Extracted search-params reading into a ReferralReader leaf component wrapped in its own <Suspense fallback={null}>, isolating the bailout boundary from the rest of the page
    • Passes referralAddress state (via useCallback-memoized setter) down to useAuctionDetail
// ReferralReader is intentionally isolated in its own Suspense boundary.
// In Next.js 16, calling useSearchParams() in a client component rendered
// inside a <Suspense> boundary triggers a 307 self-redirect loop during SSR.
function ReferralReader({ onRef }: { onRef: (addr: string | null) => void }) {
  const searchParams = useSearchParams();
  const ref = searchParams.get("referralAddress") || searchParams.get("ref");
  useEffect(() => {
    onRef(ref ?? null);
    return () => { onRef(null); };
  }, [ref, onRef]);
  return null;
}

// In AuctionDetailClient:
const handleRef = useCallback((addr: string | null) => setReferralAddress(addr), []);
// ...
<Suspense fallback={null}>
  <ReferralReader onRef={handleRef} />
</Suspense>

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cryptoart-studio-mvp Ready Ready Preview, Comment Jun 26, 2026 2:41pm

Request Review

Copilot AI added 3 commits June 26, 2026 14:35
Extract useSearchParams() out of useAuctionDetail hook and into a
dedicated ReferralReader component wrapped in its own <Suspense>
boundary.

In Next.js 16, calling useSearchParams() inside a client component
that is rendered within a <Suspense> boundary triggers a 307 self-
redirect loop during SSR, causing listing pages to render blank.

Changes:
- useAuctionDetail.ts: remove useSearchParams() call; accept
  referralAddress as an optional prop instead
- listing/[listingId]/AuctionDetailClient.tsx: remove top-level
  useSearchParams() call; add ReferralReader component that reads
  search params inside its own <Suspense fallback={null}> boundary;
  pass referralAddress state to useAuctionDetail

Fixes #175
Copilot AI changed the title [WIP] Fix blank listing detail pages due to self-redirect loop in Next.js 16 fix: eliminate useSearchParams self-redirect loop on listing detail pages Jun 26, 2026
Copilot finished work on behalf of mxjxn June 26, 2026 14:38
Copilot AI requested a review from mxjxn June 26, 2026 14:38
@mxjxn
mxjxn marked this pull request as ready for review June 26, 2026 14:41
@mxjxn
mxjxn merged commit a7ebe0b into main Jun 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants