Skip to content

fix(core): let an empty api.subDomainPrefix replace the default - #3578

Merged
hellofanny merged 5 commits into
3.xfrom
fix/subdomain-prefix-override-v3
Nov 9, 2026
Merged

hellofanny merged 5 commits into
3.xfrom
fix/subdomain-prefix-override-v3

Conversation

@hellofanny

@hellofanny hellofanny commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

A store that sets api.subDomainPrefix: [] in discovery.config.js still ends up with ['www'], so there is no way to stop www. from being stripped from the host sent to Checkout.

discovery.config.js merges the default config with the store config using deepmerge, which concatenates arrays. The default is subDomainPrefix: ['www'], so [] becomes ['www'].

The commerce client uses that array to remove the prefix from x-forwarded-host. With www always present, Checkout receives the root domain and sets checkout.vtex.com, CheckoutOrderFormOwnership, CheckoutLocale and CheckoutDataAccess on it. Calls made by the browser straight to /api/checkout set the same cookies on www.<domain>, so they are sent duplicated and the Cookie header can exceed the server header limit.

How it works?

  • New mergeDiscoveryConfig helper (src/utils/mergeDiscoveryConfig.js), used for every merge in discovery.config.js. It works like deepmerge, except that an empty subDomainPrefix replaces the default.
  • Any non-empty subDomainPrefix is still appended to ['www'], exactly as today. This keeps stores that set a custom prefix (e.g. ['shop']) and rely on www being stripped too working unchanged.
  • next.config.js prints a warning at build/dev time when subDomainPrefix is [] and secureSubdomain is on another host, since Checkout cookies set on the storefront host are not sent to it.

Behavior change

Only stores that set api.subDomainPrefix: [] are affected: today that value is ignored, and after this change www. is no longer stripped, so Checkout cookies are set on www.<domain> instead of <domain>. Stores that don't set the field, or set any non-empty value, keep the current behavior.

Cookies already set on the root domain stay in the browser until they expire or are removed, so returning visitors keep sending both copies for a while.

How to test it?

  • cd packages/core && pnpm jest test/utils/mergeDiscoveryConfig.test.ts
  • Set api.subDomainPrefix: [] in a store, call /api/graphql (e.g. ValidateCartMutation) with Host: www.<domain> and check that the Checkout cookies come with domain=www.<domain> instead of <domain>. Without the field, or with ['shop'], they stay on <domain>.
  • Set api.subDomainPrefix: [] with secureSubdomain on another host (e.g. https://secure.<domain>) and check the warning on next build / next dev.

Starters Deploy Preview

References

Checklist

PR Title and Commit Messages

PR Description

  • Added a label according to the PR goal - bug

Dependencies

  • No changes to pnpm-lock.yaml

Documentation

  • PR description

🤖 Generated with Claude Code

deepmerge concatenates arrays, so the default ['www'] was always kept and
a store setting api.subDomainPrefix: [] still ended up with ['www']. That
made the commerce client strip "www." from X-FORWARDED-HOST, so Checkout
cookies were set on the root domain and duplicated the ones set on www.

Merge discovery configs through a helper that takes the store value for
subDomainPrefix as is. Other arrays keep being concatenated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hellofanny hellofanny added the bug Something isn't working label Nov 6, 2026
Addresses the Sonar finding on mergeDiscoveryConfig.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/graphql-utils

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

commit: 1089003

@hellofanny
hellofanny marked this pull request as ready for review November 7, 2026 16:08
@hellofanny
hellofanny requested a review from a team as a code owner November 7, 2026 16:08
@hellofanny
hellofanny requested review from lemagnetic and ommeirelles and removed request for a team November 7, 2026 16:08
Overriding every subDomainPrefix value changed the behavior of stores
that set a custom prefix (e.g. ['shop']) and still relied on 'www' being
appended. Now only [] replaces the default; any other value is appended
to ['www'] as before, so existing configs keep working.

Also warn at build time when subDomainPrefix is [] and secureSubdomain
is on another host, since Checkout cookies set on the storefront host
are not sent to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hellofanny hellofanny changed the title fix(core): let the store config override api.subDomainPrefix fix(core): let an empty api.subDomainPrefix replace the default Nov 9, 2026
hellofanny and others added 2 commits November 9, 2026 12:00
…lid URLs

Apply the empty-array override only to api.subDomainPrefix instead of any
key with that name, and make the build warning report a storeUrl or
secureSubdomain that cannot be parsed instead of silently skipping it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sonar was reporting 47.5% coverage on new code even though the unit tests
cover mergeDiscoveryConfig.js fully: other test files load that module
through discovery.config.js, and the coverage of the lines only exercised
by its own test was lost when the reports were merged.

Keep the warning in a module that only next.config.js and its own test
load, so its coverage is reported correctly. Behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hellofanny
hellofanny merged commit 895a7c1 into 3.x Nov 9, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants