Skip to content

Fix theme dev falling back to the live theme after Storefront API and cart requests - #9068

Open
duyhai wants to merge 1 commit into
Shopify:mainfrom
duyhai:fix/theme-dev-cookie-auth-session
Open

duyhai wants to merge 1 commit into
Shopify:mainfrom
duyhai:fix/theme-dev-cookie-auth-session

Conversation

@duyhai

@duyhai duyhai commented Nov 4, 2026 •

Copy link
Copy Markdown

WHY are these changes introduced?

Since 4.0, theme dev stores _shopify_essential from every proxied response as the dev session cookie, including Storefront API passthrough requests (/api/*/graphql.json) and cart/checkout/account requests, which are sent without the dev session's credentials. Those responses carry a cookie that isn't bound to the development theme, so later renders use the live theme. HTML renders hit Theme ID mismatch and refresh the session, and Section Rendering API requests (?sections=<id>) silently return null, since the live theme has no section with that id.

Storefront scripts that Shopify injects make these requests on most storefronts.

WHAT is this pull request doing?

Only store _shopify_essential from requests sent with the dev session's credentials. The browser still receives the Set-Cookie header.

How to manually test your changes?

  1. Run shopify theme dev --verbose on a store whose pages call the Storefront API, and browse a few pages in the preview.
  2. Before: Theme ID mismatch: expected <dev> but got <live>; refreshing session... repeats in the terminal, and fetch('/collections/all?sections=<section-id>') in the preview's console intermittently returns {"<section-id>": null}.
  3. After: neither happens.

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

🤖 Generated with Claude Code

@duyhai
duyhai requested a review from a team as a code owner November 4, 2026 18:37
@duyhai

duyhai commented Nov 4, 2026

Copy link
Copy Markdown
Author

I have signed the CLA!

…h proxy responses

Only store `_shopify_essential` from requests sent with the dev session's
credentials. Storefront API passthrough and cart/checkout/account
requests get a cookie that isn't bound to the development theme, which
made later renders use the live theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@duyhai
duyhai force-pushed the fix/theme-dev-cookie-auth-session branch from 517eeb4 to f3ebb67 Compare November 5, 2026 18:37
@duyhai

duyhai commented Nov 5, 2026

Copy link
Copy Markdown
Author

Evidence from a real store (same theme and commit, theme dev 5.0.0 in GitHub Actions with a Theme Access password, 46-test Playwright suite):

_shopify_essential stored from /api/*/graphql.json Theme ID mismatch session refreshes
5.0.0 as released 40 50
5.0.0 with this change applied to the built bundle 0 (40 skipped) 0

On 5.0.0 the same suite also logged 42 null sections from the Section Rendering API; 3.94.3 logs none. The passthrough was added in 4862208 (4.0.0). I only saw Storefront API responses set the cookie; the cart/checkout/account exclusion applies the same rule, since those requests are also sent without the devtools Bearer token since 196cea0.

Related forum report (awaiting moderation): https://community.shopify.dev/c/shopify-cli-libraries/14

This branch has not been deployed

No deployments
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.

1 participant