~/gvndsxnkr
cd ../notes

// shopify · frontend · 5 min read

Five Shopify Hydrogen Gotchas from a Production Storefront

Worker-runtime promises, a search that ignores handles, a silent account outage and free-gift cart lines on a headless Shopify store.

I work on a headless Shopify storefront for a D2C skincare brand, built with Hydrogen (Shopify's React Router stack) and deployed to Oxygen, Shopify's edge hosting. Hydrogen removes most of the plumbing, but a production store finds the corners. These five each cost me a debugging session, so they get written down.

1. A shared promise that Oxygen won't share

The store shows its live offers (free shipping thresholds, automatic discounts) on almost every page. To avoid fetching them twice when two loaders asked at once, I cached the in-flight request in a module variable:

let inFlight: Promise<StoreOffers> | null = null;

export function getOffers() {
  if (inFlight) return inFlight;
  inFlight = Promise.allSettled([load(OFFERS_QUERY), load(FREE_SHIPPING_QUERY)])
    .then(toOffers)
    .finally(() => { inFlight = null; });
  return inFlight;
}

On a long-running Node server that's a common trick. Oxygen is a worker runtime: requests share the module, but I/O started by one request can't be awaited and resolved by another. Concurrent requests hung or failed in ways that looked random.

Fix: each request fetches its own offers. Deduplication within one request is still fine. Across requests it needs real caching, and Hydrogen's storefront.query cache strategies are the right tool for that, not a module variable.

2. products(query: "handle:...") doesn't filter by handle

The wishlist stores product handles in the browser and loads them on the wishlist page. The obvious query:

products(first: $first, query: "handle:face-wash OR handle:moisturiser") { ... }

It returned products, just not the right ones. The Storefront API's search ignored the handle filter and returned the first products in the catalogue, so only wishlisted items that happened to be early in the catalogue showed up. For most customers the wishlist looked empty.

Fix: look each product up directly, with GraphQL aliases so it's still one request:

query Wishlist {
  p0: product(handle: "face-wash") { ...WishlistProduct }
  p1: product(handle: "moisturiser") { ...WishlistProduct }
}

Missing or deleted products come back as null and are skipped, and the saved order is kept.

3. A Hydrogen upgrade that 500'd every account page

After upgrading Hydrogen, /account, order history, order details, profile and addresses all returned 500. The error, once I found it, was precise: Expected a Customer Account API document.

The new Customer Account client only accepts documents built with its own gql() tag. Our context adapter passed plain query strings, which used to work.

import { gql as customerAccountGql } from "@shopify/hydrogen";

const { data, errors } = await graphql(customerAccountGql(document), { accessToken, variables });
if (errors?.length) console.error(`[customerAccount] ${operationName}`, errors.map((e) => e.message).join("\n"));

The second half matters as much as the first. The failure had been silent because GraphQL errors weren't logged. Now they are, the same way the storefront adapter logs them.

4. Free gifts have to follow Shopify, not the other way round

The brand runs "buy 2 get 1 free" offers as automatic Buy X Get Y discounts in Shopify. Shopify discounts the free unit, but it doesn't add it to the cart, and customers expect to see their gift.

So the cart keeps gift lines in sync after every change:

  • When a product reaches X paid units, the free unit is added.
  • If paid units drop below X, the gift is removed.
  • If Shopify doesn't price the added unit at zero (the discount changed or ended), it's taken back out.
  • Gift lines have no quantity or remove controls; they follow the paid units.

An early version kept a hard-coded fallback list of gift offers for when the live discounts couldn't be read. It drifted from Shopify within days. Now offers come only from Shopify's live automatic discounts: if the merchant ends a promotion, the storefront stops promising it.

5. Variant options leaking into product URLs

Hydrogen used to ship a helper that wrote the selected variant's options into the URL (?Size=100ml). A Hydrogen release removed it, and I ported it back unchanged. Shortly after, product URLs started collecting option parameters, which shared links and canonical URLs didn't need. The fix was to delete the helper rather than patch it. The selected variant still works; the URL just stays clean.

The common thread

Headless commerce moves the storefront onto your code, but the source of truth stays in Shopify. Most of these bugs came from assuming something about Shopify's runtime or APIs instead of checking it: that the worker behaves like Node, that search filters by handle, that the account client takes strings, that a hard-coded offer list stays true. The fixes all point back at Shopify as the authority.

Headless stores also have SEO traps a classic theme doesn't, like routes that render an empty page with 200 instead of 404, and old myshopify.com or preview hosts staying indexable. I built a separate audit tool for those, described in the case study Technical SEO Audit Tool.

  • #Shopify
  • #Frontend