Skip to content

fix(hydrogen): storefrontRedirect now works with Single Fetch client-side navigations#3762

Merged
fredericoo merged 1 commit into
mainfrom
worktree-fix-storefront-redirect-single-fetch
May 18, 2026
Merged

fix(hydrogen): storefrontRedirect now works with Single Fetch client-side navigations#3762
fredericoo merged 1 commit into
mainfrom
worktree-fix-storefront-redirect-single-fetch

Conversation

@fredericoo
Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Fixes #3738

React Router v7's Single Fetch protocol changed how client-side data requests are made: from ?_data=route/id query params to a .data pathname suffix (e.g. /old-page.data). storefrontRedirect was checking searchParams.has('_data') which no longer matches, causing all client-side navigations to redirected URLs to silently return 404s instead of following the redirect. Full-page navigations were unaffected.

WHAT is this pull request doing?

Detects Single Fetch soft navigations via the .data pathname suffix, strips it to recover the real pathname, and returns the correct 204 + X-Remix-Redirect headers that React Router's turbo-stream protocol expects.

Handles all three URL patterns that React Router's singleFetchUrl produces:

  • /page.data — standard
  • /_root.data — root route (non-trailing-slash-aware)
  • /page/_.data — trailing-slash-aware

Also strips the _routes query param (replaces _data from the old protocol) before the SFAPI redirect lookup.

HOW to test your changes?

  1. Set up a Storefront API redirect (e.g., /old-page/new-page) in Shopify admin
  2. Navigate directly to /old-page — should 301 redirect (this already worked)
  3. From any page, click a link to /old-page — should now redirect via client-side navigation (this was broken)

Or run the new tests:

# Unit tests (17 tests)
cd packages/hydrogen && npx vitest run src/routing/redirect.test.ts

# E2E tests (2 tests — full-page + client-side navigation)
npx playwright test --project=skeleton e2e/specs/skeleton/storefrontRedirect.spec.ts

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or functional changes.
  • I've added tests to cover my changes
  • I've added or updated the documentation

…side navigations

React Router v7's Single Fetch protocol changed how client-side data
requests are made: from `?_data=route/id` query params to a `.data`
pathname suffix. `storefrontRedirect` was checking `searchParams.has('_data')`
which no longer matches, causing all client-side navigations to redirected
URLs to silently fail with 404s instead of following the redirect.

Key changes:
- Detect soft navigations via `.data` pathname suffix instead of `_data` query param
- Handle all three React Router Single Fetch URL patterns:
  `/page.data` (standard), `/_root.data` (root route), `/page/_.data` (trailing-slash-aware)
- Return HTTP 204 (not 200) for soft navigation redirect responses, matching
  what React Router's turbo-stream protocol expects
- Strip `_routes` query param (replaces `_data`) before SFAPI redirect lookup
- Add e2e Playwright tests with MSW for both full-page and client-side redirect flows

Fixes #3738

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shopify
Copy link
Copy Markdown
Contributor

shopify Bot commented May 14, 2026

Oxygen deployed a preview of your worktree-fix-storefront-redirect-single-fetch branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2026 4:25 PM

Learn more about Hydrogen's GitHub integration.

@fredericoo fredericoo marked this pull request as ready for review May 14, 2026 18:01
@fredericoo fredericoo requested a review from a team as a code owner May 14, 2026 18:01
@fredericoo fredericoo merged commit d17057e into main May 18, 2026
22 checks passed
@fredericoo fredericoo deleted the worktree-fix-storefront-redirect-single-fetch branch May 18, 2026 15:59
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.

storefrontRedirect doesn't work for client side navigation redirects

2 participants