Repository navigation
feat: Handle i18n config from subdomain locales strategy - #3143
Merged
Merged
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
lariciamota
marked this pull request as ready for review
December 4, 2025 21:23
lariciamota
requested review from
hellofanny and
renatamottam
and removed request for
a team
December 4, 2025 21:23
hellofanny
reviewed
Dec 9, 2025
hellofanny
reviewed
Dec 9, 2025
hellofanny
reviewed
Dec 9, 2025
hellofanny
requested review from
lemagnetic and
ommeirelles
and removed request for
renatamottam
December 9, 2025 16:35
hellofanny
approved these changes
Dec 9, 2025
Contributor
Author
AFAIK, the |
lariciamota
added a commit
that referenced
this pull request
Dec 24, 2025
## What's the purpose of this pull request? Implements a locale/hostname validation system that ensures URLs match the correct locale configuration based on the hostname. The feature prevents invalid locale/hostname combinations and returns appropriate 404 responses when configurations don't match. We want to support multiple locales and they can be configured with different URL structures: - **Subdomain bindings**: A hostname dedicated to a locale (e.g., `canada.brandless.fast.store` → `fr-CA`) - **Path-based bindings**: A hostname that serves multiple locales via paths (e.g., `brandless.fast.store/en-US`, `brandless.fast.store/it-IT`) Without validation, users could access invalid combinations like: - `brandless.fast.store/fr-CA/products` → should be 404, as `fr-CA` is only bound to `canada.brandless.fast.store` - `canada.brandless.fast.store/en-US/products` → should be 404, as `en-US` is not bound to this hostname ## How it works? ### SSR & Client-Side Validation This implementation handles both Server-Side Rendered (SSR) and Static Site Generated (SSG) pages: #### SSR Pages (e.g., `/pvt/account/*`) - **When**: Page uses `getServerSideProps` - **Where**: Server-side before rendering - **How**: `withLocaleValidationSSR` HOC wraps `getServerSideProps` - **Result**: Returns `notFound: true` → Next.js serves 404 page - **Benefit**: User never sees the invalid page, better SEO #### SSG Pages (e.g., PLPs, PDPs) - **When**: Page uses `getStaticProps` (pre-generated at build time) - **Where**: Client-side after hydration - **How**: `useEffect` in `_app.tsx` validates after mount - **Result**: Redirects to `/404` with original path in query string - **Trade-off**: Page loads before redirect, but SSG pages remain fast ps.: The same solution from SSR doesn't work on SSG because we don't have access to hostname on `getStaticProps`. ps2.: Middleware would work for this use case, but we decided to not use it to be cost efficient. #### Validation logic 1. **Localhost bypass**: Allows all locales on `localhost` and `127.0.0.1` for development tests 2. **Binding check**: Verifies if the locale has a binding for the hostname - Checks all bindings for the given locale - Matches if `binding.url` hostname equals the request hostname ## How to test it? Configure your `etc/hosts` like explained in the previous [PR](#3143), then test navigating through the store and changing domains/paths. In the discovery.config.default, put `enableFaststoreMyAccount` as `true` to test the `/pvt/account` pages. ### Example Scenarios (based on mock) #### Valid Combinations ✅ | URL | Type | Result | | -------------------------------------------- | ---------------- | ------- | | `brandless.fast.store:3000/pt-BR/apparel` | Path-based | ✅ Valid | | `brandless.fast.store.com.br:3000/pt-BR` | Subdomain | ✅ Valid | | `canada.brandless.fast.store:3000/fr-CA` | Subdomain | ✅ Valid | | `brandless.fast.store:3000/en-US/pvt/account` | Path-based (SSR) | ✅ Valid | #### Invalid Combinations ❌ | URL | Why Invalid | Result | | ----------------------------------------------- | ------------------------------------ | -------------- | | `brandless.fast.store:3000/fr-CA` | fr-CA only bound to canada subdomain | ❌ 404 (Client) | | `canada.brandless.fast.store:3000/en-US/apparel` | en-US not bound to canada subdomain | ❌ 404 (Client) | | `brandless.fast.store.com:3000/pt-BR/apparel` | pt-BR not bound to .com | ❌ 404 (Client) | | `canada.brandless.fast.store:3000/pt-BR/pvt/account` | pt-BR not bound to canada | ❌ 404 (SSR) | ## References - [Jira task](https://vtex-dev.atlassian.net/browse/SFS-2990) - Slack threads ([1](https://vtex.slack.com/archives/C09CZGYTXEE/p1764883650666369), [2](https://vtex.slack.com/archives/C09CZGYTXEE/p1765564641414739))
lemagnetic
added a commit
that referenced
this pull request
Mar 5, 2026
## What's the purpose of this pull request? Removing hardcoded labels: - #3099 - #3102 - #3107 - #3104 - #3103 - #3125 - #3131 - #3116 - #3142 - #3192 Setting Up locales - #3141 - #3143 - #3147 - #3156 - #3162 - #3145 - #3164 - #3169 - #3171 - #3176 - #3180 - #3169 custom path - #3185 - #3162 - #3156 - #3170 Components - #3093 - #3175 Fetching content - #3165 Others - #3176 - #3171 - #3181 - #3189 - #3205 ## How to test locally? - Run `pnpm I` (install all the new dependencies and needed packages) - If you want to try localization feature, go to`/discovery.config.default.js`: Enable localization: ``` localization: { enabled: true } ``` - Run `node packages/cli/bin/run.js generate-i18n ./packages/core` to fetch the bindings If the contentSource is not set to content platform yet, you will see a message to update to it. > contentSource: { > type: 'CP', > },⚠️ Note: Ensure the url is set to localhost for local testing. These locale bindings are generated in `discovery.config` after running the generate-i18n command. ```diff localization: { enabled: true, defaultLocale: 'en-US', regions: {...}, locales: { 'pt-BR': { ... bindings: [ { currencyCode: 'BRL', - url: 'https://brandless.fast.store/pt-BR', + url: 'http://localhost:3000/pt-BR', salesChannel: '2', isDefault: true, locales: [ { code: 'pt-BR', isDefault: true, }, ], }, ], }, 'it-IT': { ... bindings: [ { currencyCode: 'EUR', - url: 'https://brandless.fast.store/it-IT', + url: 'http://localhost:3000/it-IT', salesChannel: '3', isDefault: true, locales: [ { code: 'it-IT', isDefault: true, }, ], }, { currencyCode: 'EUR', - url: 'https://brandless.fast.store/europe/it', + url: 'http://localhost:3000/europe/it', salesChannel: '3', isDefault: false, locales: [ { code: 'it-IT', isDefault: true, }, ], }, ], }, 'en-US': { code: 'en-US', name: 'English', languageCode: 'en', languageName: 'English', script: 'Latn', textDirection: 'ltr', regionCode: 'US', bindings: [ { currencyCode: 'USD', - url: 'https://brandless.fast.store', + url: 'http://localhost:3000, salesChannel: '1', isDefault: true, locales: [ { code: 'en-US', isDefault: true, }, ], }, ], }, ... } ``` - Go to /packages/core and run `npmn dev` --------- Co-authored-by: Larícia Mota <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: Otavio Moreira Meirelles <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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?
Update the i18n next config to handle subdomain locales strategy.
How it works?
The function
buildI18nDomainsadds the binding URLs domains in the domains array (i18n next config) if there is no path in the URL.How to test it?
Test that the path strategy continues working by accessing the locales paths, like
/pt-BR.To test the domains strategy I configured some routing test domains in
/etc/hosts, to do that you can follow these steps:sudo vi /etc/hostsThen, run the core and you can test paths and subdomains strategies freely.
Starters Deploy Preview
References