Skip to content

fix(theme): preserve dev preview theme across SFR redirects#7642

Open
EvilGenius13 wants to merge 1 commit into
mainfrom
fix/theme-dev-redirect-manual
Open

fix(theme): preserve dev preview theme across SFR redirects#7642
EvilGenius13 wants to merge 1 commit into
mainfrom
fix/theme-dev-redirect-manual

Conversation

@EvilGenius13
Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

The storefront renderer fetch call was using fetch's default redirect behavior ('follow'), which silently dropped the intermediate Set-Cookie headers that bind _shopify_essential to the dev theme. After SFR migrated preview_theme_id from server-side storage into the cookie (shop/world 2026-03-27), this latent issue surfaced as the dev preview occasionally rendering the live theme.

Set redirect: 'manual' on storefront-renderer fetches and patch response headers (Set-Cookie capture + Location rewrite) on 3xx so the browser can follow the redirect cleanly while we keep the dev-bound session cookie.

WHAT is this pull request doing?

on 3xx so the browser can follow the redirect cleanly while we keep the dev-bound session cookie.

How to test your changes?

Post-release steps

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

@github-actions github-actions Bot added the Area: @shopify/theme @shopify/theme package issues label May 26, 2026
The storefront renderer fetch call was using fetch's default redirect
behavior ('follow'), which silently dropped the intermediate Set-Cookie
headers that bind _shopify_essential to the dev theme. After SFR migrated
preview_theme_id from server-side storage into the cookie (shop/world
2026-03-27), this latent issue surfaced as the dev preview occasionally
rendering the live theme.

Set redirect: 'manual' on storefront-renderer fetches and patch response
headers (Set-Cookie capture + Location rewrite) on 3xx so the browser can
follow the redirect cleanly while we keep the dev-bound session cookie.

Fixes #7344
@EvilGenius13 EvilGenius13 force-pushed the fix/theme-dev-redirect-manual branch from 44ea01c to 932be3d Compare May 26, 2026 17:28
rawResponse: Response,
patchCallback?: (html: string) => string | undefined,
): Promise<Response> {
const response = patchProxiedResponseHeaders(ctx, rawResponse)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flipping this to happen earlier makes sure the cookie is available to our session for any following requests.

response = await fetch(url, {
method: 'POST',
body: bodyParams,
redirect: 'manual',
Copy link
Copy Markdown
Contributor Author

@EvilGenius13 EvilGenius13 May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the cookie visible by not having node drop it on a redirect.

@EvilGenius13 EvilGenius13 marked this pull request as ready for review May 26, 2026 18:17
@EvilGenius13 EvilGenius13 requested a review from a team as a code owner May 26, 2026 18:17
Copilot AI review requested due to automatic review settings May 26, 2026 18:17
@EvilGenius13 EvilGenius13 requested a review from a team as a code owner May 26, 2026 18:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes theme dev preview sessions occasionally losing the dev preview theme after Storefront Renderer (SFR) redirects by preventing server-side fetch from auto-following 3xx responses (so intermediate Set-Cookie headers aren’t dropped) and ensuring redirect responses have their headers patched before returning to the browser.

Changes:

  • Set redirect: 'manual' on SFR fetch calls in the storefront renderer to preserve intermediate Set-Cookie headers.
  • Patch and return 3xx rendering responses (cookie capture + Location rewrite) instead of returning the raw response unmodified.
  • Add targeted unit tests covering manual redirect behavior and 3xx header patching; add a patch changeset.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/theme/src/cli/utilities/theme-environment/storefront-renderer.ts Uses manual redirect handling for SFR fetches to preserve intermediate redirect cookies.
packages/theme/src/cli/utilities/theme-environment/storefront-renderer.test.ts Adds tests ensuring GET/POST render requests do not auto-follow 3xx responses.
packages/theme/src/cli/utilities/theme-environment/proxy.ts Ensures 3xx responses are header-patched (cookies + Location) before returning.
packages/theme/src/cli/utilities/theme-environment/proxy.test.ts Adds tests for _shopify_essential capture and Location rewriting on 3xx responses.
.changeset/tidy-bats-prove.md Declares a patch release note for the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'@shopify/theme': patch
---

Fix `theme dev` preview occasionally rendering the live theme by preserving shopify cookie in redirects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: @shopify/theme @shopify/theme package issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants