Skip to content

fix: locale validation pvt routes#3364

Closed
ArthurTriis1 wants to merge 2 commits into
devfrom
fix/locale-validation-pvt-routes
Closed

fix: locale validation pvt routes#3364
ArthurTriis1 wants to merge 2 commits into
devfrom
fix/locale-validation-pvt-routes

Conversation

@ArthurTriis1

@ArthurTriis1 ArthurTriis1 commented Jun 1, 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

Release Notes

  • Bug Fixes
    • Localization validation now correctly respects the localization enabled/disabled setting, skipping unnecessary checks when disabled.
    • Private routes are now properly exempted from locale validation, preventing validation failures on internal endpoints.

ArthurTriis1 and others added 2 commits May 29, 2026 18:21
…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>
…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>
@ArthurTriis1 ArthurTriis1 requested a review from a team as a code owner June 1, 2026 14:23
@ArthurTriis1 ArthurTriis1 requested review from gabpaladino and renatamottam and removed request for a team June 1, 2026 14:23
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR adds two early-exit conditions for locale validation: bypassing validation when localization is disabled via storeConfig.localization?.enabled, and skipping validation for private routes matching /pvt/ paths. Both utilities now short-circuit to avoid unnecessary hostname/locale binding checks.

Changes

Localization Validation Gating

Layer / File(s) Summary
Config-based gating in validateLocaleForHostname
packages/core/src/utils/localization/validateLocaleForHostname.ts
Import source for storeConfig changes from default config to the active config. An early-return exits with true when storeConfig.localization?.enabled is falsy, skipping all downstream hostname-binding validation.
Private route bypass in withLocaleValidationSSR
packages/core/src/utils/localization/withLocaleValidation.ts
Extracts pathname from req.url by stripping query parameters. Validation is skipped and the original handler delegates immediately when the pathname starts with /pvt/.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • vtex/faststore#3358: Identical code-level fixes to validateLocaleForHostname import and short-circuit logic, plus /pvt/ pathname bypass in withLocaleValidationSSR.
  • vtex/faststore#3296: Also gates localization behavior behind storeConfig.localization?.enabled in validateSession to skip locale/currency/channel recomputation.

Suggested labels

bug

Suggested reviewers

  • renatomaurovtex

Poem

🔒 When locales must hide behind the gate,
And /pvt/ paths bypass the validate,
The config's word becomes the only fate—
No binding checks for routes that authenticate. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check ✅ Passed The title 'fix: locale validation pvt routes' directly and clearly describes the main changes: fixing locale validation for /pvt/ routes, which is the primary bug fix in this changeset.

✏️ 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 Jun 1, 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.

@sonar-workflows

Copy link
Copy Markdown

@hellofanny hellofanny changed the title Fix/locale validation pvt routes Fix: locale validation pvt routes Jun 1, 2026

@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.

Approving! It's already merged on main

@lemagnetic taggin you just to let you know 😉

@hellofanny hellofanny changed the title Fix: locale validation pvt routes fix: locale validation pvt routes Jun 1, 2026
@hellofanny hellofanny closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants