Repository navigation
fix(core): let an empty api.subDomainPrefix replace the default - #3578
Merged
Merged
Conversation
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]>
Addresses the Sonar finding on mergeDiscoveryConfig. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/graphql-utils
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
hellofanny
marked this pull request as ready for review
November 7, 2026 16:08
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]>
eduardoformiga
approved these changes
Nov 9, 2026
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the purpose of this pull request?
A store that sets
api.subDomainPrefix: []indiscovery.config.jsstill ends up with['www'], so there is no way to stopwww.from being stripped from the host sent to Checkout.discovery.config.jsmerges the default config with the store config usingdeepmerge, which concatenates arrays. The default issubDomainPrefix: ['www'], so[]becomes['www'].The commerce client uses that array to remove the prefix from
x-forwarded-host. Withwwwalways present, Checkout receives the root domain and setscheckout.vtex.com,CheckoutOrderFormOwnership,CheckoutLocaleandCheckoutDataAccesson it. Calls made by the browser straight to/api/checkoutset the same cookies onwww.<domain>, so they are sent duplicated and theCookieheader can exceed the server header limit.How it works?
mergeDiscoveryConfighelper (src/utils/mergeDiscoveryConfig.js), used for every merge indiscovery.config.js. It works likedeepmerge, except that an emptysubDomainPrefixreplaces the default.subDomainPrefixis still appended to['www'], exactly as today. This keeps stores that set a custom prefix (e.g.['shop']) and rely onwwwbeing stripped too working unchanged.next.config.jsprints a warning at build/dev time whensubDomainPrefixis[]andsecureSubdomainis 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 changewww.is no longer stripped, so Checkout cookies are set onwww.<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.tsapi.subDomainPrefix: []in a store, call/api/graphql(e.g.ValidateCartMutation) withHost: www.<domain>and check that the Checkout cookies come withdomain=www.<domain>instead of<domain>. Without the field, or with['shop'], they stay on<domain>.api.subDomainPrefix: []withsecureSubdomainon another host (e.g.https://secure.<domain>) and check the warning onnext build/next dev.Starters Deploy Preview
References
Backport of fix(core): let an empty api.subDomainPrefix replace the default #3577 (dev).
Checkout sets the cookie domain from
X-FORWARDED-HOST(checked against the publicorderFormendpoint).Checklist
PR Title and Commit Messages
PR Description
bugDependencies
pnpm-lock.yamlDocumentation
🤖 Generated with Claude Code