Skip to content

Fix theme profile for URLs with a query string and report redirects - #8989

Merged
isaacroldan merged 1 commit into
mainfrom
theme-profile-redirect-error
Oct 23, 2026
Merged

isaacroldan merged 1 commit into
mainfrom
theme-profile-redirect-error

Conversation

@MillanWangShopify

@MillanWangShopify MillanWangShopify commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Vault issue: https://vault.shopify.io/teams/16949-Dev-Experience/issues/92474-error-bad-response-301

shopify theme profile --url <path> fails with Error: Bad response: 301: , with no hint about the cause, and it's reported to Bugsnag as an unexpected crash.

  • About two thirds of the 301s come from a --url with a query string. profile passed the whole --url as the path, and the renderer appends its own ?_fd=0&pb=0. That built /search?q=kw?_fd=0&pb=0, which drops _fd=0, so stores with a custom primary domain redirect to that domain. theme dev doesn't have this bug because it already passes the path and query separately.
  • The rest are pages that redirect on the storefront (URL redirects, markets), plus a few 302s to /password on password-protected stores.

WHAT is this pull request doing?

  • Splits --url into a path and a query before rendering. The #fragment is dropped, and a user-supplied _fd or pb is removed so the renderer's values always apply (the param list is now exported from storefront-renderer.ts). An absolute --url is accepted, and only its path and query are used; the flag description now says so.
  • Rejects a --url that can't be parsed (it used to throw a TypeError) or that starts with // (it was parsed as a host, so another page was profiled).
  • Raises an AbortError when the page redirects, and shows the destination without _fd/pb:
    • a store-relative destination is suggested as the next --url,
    • an absolute destination, which can be another host such as customer accounts, is shown in full, and its path is suggested only "if that page is on your storefront",
    • a destination with the same path and query as the request isn't suggested, so scripts and agents don't retry the same redirect,
    • a redirect to /password suggests checking --store-password.
      Redirects aren't followed automatically.
  • Raises an AbortError for other non-200 responses, with the status, the request ID, and the body only when it's JSON or short (never a full HTML page). This includes storefront 5xx responses: they aren't caused by the user, but the CLI can't act on them, so reporting them as CLI crashes in Bugsnag only adds noise.

Out of scope: why a password-protected preview render can still get a 302 to /password after the password check passes.

Before:

Error: Bad response: 301:

After (page that redirects):

The page /pages/old redirects (301) instead of rendering, so it can't be profiled.
It redirects to /pages/new. Run the command again with --url "/pages/new".

How to manually test your changes?

On a dev store you own, ideally one with a custom primary domain:

pnpm shopify theme profile --store <store> --url "/search?q=test" --json
pnpm shopify theme profile --store <store> --url "/collections/all?page=2" --json

Both should return a profile. Then add a URL redirect (Admin → Content → Menus → URL redirects) and profile its source path: the error should suggest the destination.

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

@MillanWangShopify
MillanWangShopify added this pull request to stack #8990 October 22, 2026 16:04
@github-actions github-actions Bot added the Area: @shopify/theme @shopify/theme package issues label Oct 22, 2026
@MillanWangShopify
MillanWangShopify marked this pull request as ready for review October 22, 2026 16:07
@MillanWangShopify
MillanWangShopify requested a review from a team as a code owner October 22, 2026 16:07
@MillanWangShopify
MillanWangShopify force-pushed the theme-profile-redirect-error branch from c24724f to 4144739 Compare October 22, 2026 17:41
@MillanWangShopify
MillanWangShopify requested a review from a team as a code owner October 22, 2026 17:41

@karreiro karreiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, @MillanWangShopify!

@isaacroldan
isaacroldan added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
Base automatically changed from theme-check-config-directory-error to main October 23, 2026 09:40
Split the --url into a path and a query before rendering. The renderer appends its own query, so a --url with a query string produced a malformed URL that dropped _fd=0, and stores with a custom primary domain answered with a 301. Reject a --url that can't be parsed, or that starts with //, instead of crashing or profiling another page.

Raise an AbortError with the redirect destination when the profiled page redirects. Only suggest a new --url when it differs from the requested one, flag destinations on other hosts, and point to --store-password for /password. Raise an AbortError for other non-200 responses too, so they are reported as expected errors instead of crashes.
@isaacroldan
isaacroldan force-pushed the theme-profile-redirect-error branch from 4144739 to e85a56f Compare October 23, 2026 09:40
@isaacroldan
isaacroldan enabled stacked auto-merge October 23, 2026 09:41
@isaacroldan
isaacroldan added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit c3d9bc6 Oct 23, 2026
29 checks passed
@isaacroldan
isaacroldan deleted the theme-profile-redirect-error branch October 23, 2026 10:03
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.

3 participants