hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

Headers.getSetCookie is not a function on Oxygen: hydrogen 2026.10.2 captureSubrequestHeaders crashes every Storefront API request

Open isobecci opened this issue 1 month ago • 1 comments

Title

Headers.getSetCookie is not a function on Oxygen: hydrogen 2026.10.2 captureSubrequestHeaders crashes every Storefront API request

Environment

  • @shopify/hydrogen 2026.10.2 (latest on npm at the time of writing)
  • React Router 8.5.1 / @react-router/dev 8.5.1, built with plain react-router build (the hydrogen() Vite plugin no longer exists in 2026.10)
  • Deployed to Oxygen (preview deployment). Local MiniOxygen (workerd 1.20260730) does not reproduce: typeof Headers.prototype.getSetCookie === "function" there.

The issue is router-version independent: the crashing code is in hydrogen itself, so the official React Router 7.15.1 template on the same Oxygen runtime should fail the same way.

Symptom

Every document request returns 500. Oxygen runtime log:

ERROR { name: 'StorefrontApiError', message: 'SFAPI request failed' }

All parallel root-loader Storefront API calls (cart, layout, header/footer menus) fail within ~30 ms of each other — no network contact is made.

Cause (captured with a temporary logging wrapper around storefrontClient)

StorefrontApiError: SFAPI request failed
  caused by TypeError: headers.getSetCookie is not a function
    at requestContext.captureSubrequestHeaders (dist/core/request-context.mjs:37)
    at dist/client/client.mjs:112
    at ... (app loaders)

captureSubrequestHeaders (dist/core/request-context.mjs:37) calls headers.getSetCookie() for every storefront response whose cache status is not hit, i.e. on practically every request. The Headers implementation in Oxygen's runtime does not expose getSetCookie, so every Storefront API request throws.

Note: the Oxygen runtime docs (https://shopify.dev/docs/storefronts/hydrogen/deploy/oxygen/runtime) state that headers.getSetCookie() is available, but the deployed runtime lacks it. This also matters because applyResponseHeaders (request-context.mjs:66) calls getSetCookie() on outgoing response headers under some conditions, so patching only storefront responses may not cover everything.

Relation to existing reports

  • #2959 reported the same error message, but only for the local preview (MiniOxygen's older workerd, hydrogen 2025.5.0).
  • #2963 proposed a polyfill for that local-preview case and was closed unmerged ("the real solution is to upgrade miniflare").
  • Neither covers the deployed Oxygen runtime, which is the case here: the production runtime itself lacks getSetCookie, and hydrogen 2026.10 has no polyfill layer anymore (the hydrogen() Vite plugin that used to polyfill fetch was removed in 2026.10).

Workaround (verified working on Oxygen)

A guarded prototype shim in the Worker entrypoint (server.ts):

if (typeof Headers.prototype.getSetCookie !== "function") {
	Headers.prototype.getSetCookie = function () {
		const value = this.get("set-cookie");
		return value ? [value] : [];
	};
}

After deploying this shim, all pages return 200 again and cart add, checkout navigation, and contact form submission (with email delivery) were verified on the preview deployment. Known limitation: multiple set-cookie values are returned as one joined entry.

Request

Either expose Headers.getSetCookie in Oxygen's runtime, or make captureSubrequestHeaders / applyResponseHeaders fall back gracefully when the method is missing.

isobecci avatar Oct 29 '26 07:10 isobecci

Looking into this — will open a PR to guard getSetCookie for Oxygen runtimes that lack it.

umeraamir69 avatar Nov 11 '26 18:11 umeraamir69