Skip to content

Send preview_theme_id on every request#7499

Open
frandiox wants to merge 2 commits intomainfrom
fd-keep-preview-theme-id
Open

Send preview_theme_id on every request#7499
frandiox wants to merge 2 commits intomainfrom
fd-keep-preview-theme-id

Conversation

@frandiox
Copy link
Copy Markdown
Contributor

@frandiox frandiox commented May 8, 2026

WHY are these changes introduced?

Related #7344, and maybe #7494

Not sure yet if this fixes the problems, though.

WHAT is this pull request doing?

Send preview_theme_id on storefront renderer requests so theme dev does not rely solely on preview state persisted in the storefront session cookie. Preserve an explicit preview_theme_id from the incoming browser query string when present.

Also clean preview_theme_id from mismatch retry and proxied redirect locations so stale/internal render params are not sent back to localhost browsers.

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

frandiox and others added 2 commits May 8, 2026 16:46
Send preview_theme_id on storefront renderer requests so theme dev does not rely solely on preview state persisted in the storefront session cookie. Preserve an explicit preview_theme_id from the incoming browser query string when present.

Also clean preview_theme_id from mismatch retry and proxied redirect locations so stale/internal render params are not sent back to localhost browsers.

Co-authored-by: OpenAI Codex <codex@openai.com>
Copilot AI review requested due to automatic review settings May 8, 2026 08:24
@frandiox frandiox requested review from a team as code owners May 8, 2026 08:24
@frandiox
Copy link
Copy Markdown
Contributor Author

frandiox commented May 8, 2026

/snapit

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label May 8, 2026
@github-actions github-actions Bot added Area: @shopify/theme @shopify/theme package issues and removed no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. labels May 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

🫰✨ Thanks @frandiox! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260508082501

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

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 updates the theme dev storefront rendering flow to always include preview_theme_id in Storefront Renderer (SFR) requests (while preserving a preview_theme_id explicitly provided by the browser), and ensures redirects don’t leak internal rendering params back to the browser—helping reduce theme ID mismatch loops when session/cookie preview state becomes unreliable.

Changes:

  • Always append preview_theme_id=<devThemeId> to SFR render requests unless the incoming query already specifies preview_theme_id.
  • Patch 3xx rendering responses after header patching and strip preview_theme_id (along with existing internal params) from redirect Location headers.
  • Drop stale preview_theme_id from the mismatch-retry redirect URL so retries aren’t pinned to an incorrect theme.

Reviewed changes

Copilot reviewed 7 out of 7 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 Injects preview_theme_id into SFR request URLs when absent.
packages/theme/src/cli/utilities/theme-environment/storefront-renderer.test.ts Updates/extends tests to assert preview_theme_id injection and preservation behavior.
packages/theme/src/cli/utilities/theme-environment/proxy.ts Applies header patching before returning 3xx and strips preview_theme_id from redirect locations.
packages/theme/src/cli/utilities/theme-environment/proxy.test.ts Adds coverage for redirect Location rewriting/removal of internal params.
packages/theme/src/cli/utilities/theme-environment/html.ts Removes stale preview_theme_id from mismatch-retry redirects.
packages/theme/src/cli/utilities/theme-environment/html.test.ts Adds assertions for passing themeId into render calls and dropping stale preview_theme_id on mismatch retry.

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

params.append('preview_theme_id', themeId)
}

// The Section Rendering API takes precendence over the Block Rendering API.
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