Skip to content

fix(core): fix locale validation for disabled localization and pvt routes#3358

Merged
hellofanny merged 2 commits into
mainfrom
fix/locale-validation-pvt-routes
Jun 1, 2026
Merged

fix(core): fix locale validation for disabled localization and pvt routes#3358
hellofanny merged 2 commits into
mainfrom
fix/locale-validation-pvt-routes

Conversation

@ArthurTriis1

@ArthurTriis1 ArthurTriis1 commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Problem

validateLocaleForHostname has three bugs that cause 404 on all SSR pages when upgrading to FastStore v4:

1. Wrong config import

The function imports from discovery.config.default.js (FastStore default config only) instead of discovery.config (merged default + store config). All other utils in the same codebase use discovery.config.

This means any locale bindings defined in the store's discovery.config.js are completely ignored during validation.

2. localization.enabled flag not respected

When localization.enabled: false, the function still runs full hostname/binding validation and returns notFound: true for any non-localhost host.

All other functions in bindingPaths.ts correctly check !storeConfig.localization?.enabled and return early — validateLocaleForHostname was the only one missing this check.

3. /pvt/ routes incorrectly validated

withLocaleValidationSSR is applied to all SSR pages including B2B portal pages under /pvt/. These are private authenticated routes that have no relationship to storefront locale routing and should never be blocked by locale validation.

Fix

  1. Import fix: discovery.config.default.jsdiscovery.config
  2. enabled check: Skip validation when localization.enabled is false, consistent with bindingPaths.ts
  3. pvt bypass: Skip locale validation for routes starting with /pvt/

Impact

Stores upgrading to v4 with localization.enabled: false (the default) were getting 404 on all SSR pages (/pvt/account, /pvt/organization-account/..., etc.) in any non-localhost environment.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Locale validation now correctly short-circuits when localization is disabled, preventing unnecessary validation and avoiding false negatives.
    • Locale validation is skipped for private/authenticated routes, ensuring those requests proceed without hostname-based locale checks and improving request handling for protected paths.

Review Change Stack

…utes

- Fix import in validateLocaleForHostname to use merged config
  ('discovery.config') instead of default-only config
  ('discovery.config.default.js'), consistent with all other utils
- Skip locale validation when localization.enabled is false,
  consistent with bindingPaths.ts behavior
- Skip locale validation for /pvt/ routes (B2B portal pages
  should not be subject to storefront locale validation)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ArthurTriis1 ArthurTriis1 requested a review from a team as a code owner May 29, 2026 21:22
@ArthurTriis1 ArthurTriis1 requested review from lariciamota and renatomaurovtex and removed request for a team May 29, 2026 21:22
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 19e190a7-d964-46ad-9321-207661477c2f

📥 Commits

Reviewing files that changed from the base of the PR and between 3312cd1 and 4916693.

📒 Files selected for processing (1)
  • packages/core/src/utils/localization/validateLocaleForHostname.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/utils/localization/validateLocaleForHostname.ts

Walkthrough

Two localization validation utilities add early-return short-circuits to skip hostname/locale binding validation in specific scenarios: when localization is disabled in store configuration, and when requests target private/authenticated routes (paths prefixed with /pvt/).

Changes

Localization Validation Short-Circuits

Layer / File(s) Summary
Localization-disabled bypass
packages/core/src/utils/localization/validateLocaleForHostname.ts
Import source updated to discovery.config. Function now returns early with true when storeConfig.localization?.enabled is falsy, bypassing hostname/locale binding validation entirely when localization is disabled.
Private route bypass
packages/core/src/utils/localization/withLocaleValidation.ts
withLocaleValidationSSR extracts the request pathname from req.url, checks if it starts with /pvt/, and if so, immediately delegates to the original getServerSidePropsFn without validating the locale against the hostname.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • vtex/faststore#3216: Also gates localization-dependent behavior on storeConfig.localization?.enabled.
  • vtex/faststore#3269: Modifies validateLocaleForHostname.ts validation and hostname handling.

Suggested labels

bug

Suggested reviewers

  • lemagnetic
  • lariciamota
  • gabpaladino

When locales nap and flags go dim,
Private paths pass by on a whim,
A short-circuit hums, validation sleeps,
Lightweight routes make lighter heaps. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the two main fixes in the changeset: locale validation for disabled localization and private routes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/locale-validation-pvt-routes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented May 29, 2026

Copy link
Copy Markdown

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.

…ocalesSettings

LocalesSettings type does not include enabled field — access it
via storeConfig.localization?.enabled as done in bindingPaths.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented May 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/api@4916693.tgz

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/cli@4916693.tgz

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/components@4916693.tgz

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/core@4916693.tgz

@faststore/diagnostics

yarn add https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@4916693.tgz

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@4916693.tgz

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/sdk@4916693.tgz

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/ui@4916693.tgz

commit: 4916693

@hellofanny hellofanny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Thanks! 🚀

@hellofanny hellofanny merged commit b742658 into main Jun 1, 2026
13 of 15 checks passed
@hellofanny hellofanny deleted the fix/locale-validation-pvt-routes branch June 1, 2026 14:06
@ArthurTriis1 ArthurTriis1 restored the fix/locale-validation-pvt-routes branch June 1, 2026 14:13
@hellofanny hellofanny added the hotfix Address critical bugs that need to be fixed immediately label Jun 1, 2026
This was referenced Jun 1, 2026
hellofanny pushed a commit that referenced this pull request Jun 1, 2026
…utes (#3358)

## Problem

`validateLocaleForHostname` has three bugs that cause 404 on all SSR
pages when upgrading to FastStore v4:

### 1. Wrong config import
The function imports from `discovery.config.default.js` (FastStore
default config only) instead of `discovery.config` (merged default +
store config). All other utils in the same codebase use
`discovery.config`.

This means any locale bindings defined in the store's
`discovery.config.js` are completely ignored during validation.

### 2. `localization.enabled` flag not respected
When `localization.enabled: false`, the function still runs full
hostname/binding validation and returns `notFound: true` for any
non-localhost host.

All other functions in `bindingPaths.ts` correctly check
`!storeConfig.localization?.enabled` and return early —
`validateLocaleForHostname` was the only one missing this check.

### 3. `/pvt/` routes incorrectly validated
`withLocaleValidationSSR` is applied to all SSR pages including B2B
portal pages under `/pvt/`. These are private authenticated routes that
have no relationship to storefront locale routing and should never be
blocked by locale validation.

## Fix

1. **Import fix**: `discovery.config.default.js` → `discovery.config`
2. **enabled check**: Skip validation when `localization.enabled` is
`false`, consistent with `bindingPaths.ts`
3. **pvt bypass**: Skip locale validation for routes starting with
`/pvt/`

## Impact

Stores upgrading to v4 with `localization.enabled: false` (the default)
were getting 404 on all SSR pages (`/pvt/account`,
`/pvt/organization-account/...`, etc.) in any non-localhost environment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Locale validation now correctly short-circuits when localization is
disabled, preventing unnecessary validation and avoiding false
negatives.
* Locale validation is skipped for private/authenticated routes,
ensuring those requests proceed without hostname-based locale checks and
improving request handling for protected paths.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/vtex/faststore/pull/3358?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix Address critical bugs that need to be fixed immediately

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants