Skip to content

fix: localization selector stale and reset selection for unsaved changes - #3301

Merged
hellofanny merged 3 commits into
devfrom
fix/localization-selector-stale
May 11, 2026
Merged

hellofanny merged 3 commits into
devfrom
fix/localization-selector-stale

Conversation

@hellofanny

@hellofanny hellofanny commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved locale and currency syncing so session changes update the UI after initial load, while still respecting user edits.
  • New Features

    • Closing the localization selector now restores session-backed locale and currency (a reset of selection state), ensuring consistent settings when the selector is dismissed.

What to test

Localization Selector Language display

  • access for example a locale path /it-IT, changes to English (en-US) and save it.
  • try to access via url /it-IT. the selector language field should be "italiano".
bug-selected-language-fixed.mov

Reset selection for unsaved changes

  • open the localization selector and select another language
  • click outside the selector without saving the changes
  • the language field should reset to the current language
reset-selection-selector.mov

Reference:
Jira task

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds session-driven synchronization to useBindingSelector (two useEffect hooks), a user-edited guard preventing session overwrites, a public reset() to re-enable syncing and restore session values, and calls reset() when the LocalizationSelector is closed.

Changes

Session State Synchronization

Layer / File(s) Summary
Import Dependencies
packages/core/src/sdk/localization/useBindingSelector.ts
useEffect added to React imports.
Session-to-State Sync Effects
packages/core/src/sdk/localization/useBindingSelector.ts
Two useEffect hooks sync localeCode and currencyCode from useSession() when session values change, gated by a user-edited flag.
User-Edit Guard
packages/core/src/sdk/localization/useBindingSelector.ts
Setting locale/currency via user actions marks a hasUserEditedSelection flag to pause session-driven syncing.
Reset API
packages/core/src/sdk/localization/useBindingSelector.ts
Adds reset() to clear the user-edited flag, restore selections from session, clear errors, and includes reset in the hook return type.
Localization Button Wiring
packages/core/src/components/ui/LocalizationButton/LocalizationButton.tsx
LocalizationButton now destructures reset from the hook and calls reset() in the LocalizationSelector onClose handler alongside closing the popover.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • vtex/faststore#3181: Modifies LocalizationButton.tsx (related callsite changes to the same component).

Suggested labels

enhancement

Suggested reviewers

  • eduardoformiga

Poem

✨ Hooks listen when the session speaks,
User choices pause the stream,
Reset returns the quiet sync,
Locale and currency dream. 🌍

🚥 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 accurately describes the main changes: fixing stale state in the localization selector and implementing a reset mechanism for unsaved user changes.

✏️ 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/localization-selector-stale

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

@eduardoformiga
eduardoformiga force-pushed the dev branch 2 times, most recently from 6c7ef8e to 4d4ac3a Compare May 7, 2026 15:18
@hellofanny
hellofanny marked this pull request as ready for review May 7, 2026 17:33
@hellofanny
hellofanny requested a review from a team as a code owner May 7, 2026 17:33
@hellofanny
hellofanny requested review from renatamottam and renatomaurovtex and removed request for a team May 7, 2026 17:33

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/sdk/localization/useBindingSelector.ts`:
- Around line 80-88: The effects always overwrite local selection when session
updates (clobbering in-progress user choices); update the two useEffect blocks
(the ones calling setLocaleCode(currentLocale ?? null) and
setCurrencyCode(currentCurrency?.code ?? null)) to only write when the local
state is empty/uninitialized or actually different and not user-modified—e.g.,
check the existing localeCode/currencyCode and only call setLocaleCode or
setCurrencyCode if localeCode is null/undefined (or different and not flagged as
user-chosen), or introduce a simple "initialized" or "userEdited" flag to
prevent overwriting user selections when useSession() resolves late. Ensure you
reference and use the existing symbols localeCode, currencyCode, setLocaleCode,
setCurrencyCode, currentLocale, and currentCurrency?.code in your guard logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 76fb1491-5f59-4b1c-9fed-b53aac9b8f72

📥 Commits

Reviewing files that changed from the base of the PR and between 4d4ac3a and f717bd7.

📒 Files selected for processing (1)
  • packages/core/src/sdk/localization/useBindingSelector.ts

@pkg-pr-new

pkg-pr-new Bot commented May 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/diagnostics

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: bc3ccea

@hellofanny hellofanny changed the title fix: attempts to fix localization selector stale fix: localization selector stale and reset selection for unsaved changes May 7, 2026
@hellofanny hellofanny self-assigned this May 7, 2026
@hellofanny hellofanny added the bug Something isn't working label May 7, 2026
@hellofanny
hellofanny requested review from eduardoformiga and lemagnetic and removed request for renatamottam and renatomaurovtex May 8, 2026 15:01
@hellofanny
hellofanny merged commit 023e52e into dev May 11, 2026
9 checks passed
@hellofanny
hellofanny deleted the fix/localization-selector-stale branch May 11, 2026 15:28
eduardoformiga added a commit that referenced this pull request May 11, 2026
## What's the purpose of this pull request?

Bring `dev` into `main` so the next CD run on `main` cuts and publishes
`@faststore/*@4.1.0`. Includes the publish-pipeline fix from #3309, so
this is also the first release that exercises the `pnpm -r publish` flow
end-to-end (broken `4.0.0` is superseded by `4.1.0` as `latest`).

## What's included since v4.0.0

- #3308 — fix: PLP "Load more products" overwriting list instead of
appending
- #3306 — feat: user details adjusts — SFS-2950
- #3304 — fix: updates schemas vtex.faststore
- #3301 — fix: localization selector stale and reset selection for
unsaved changes
- `d1e40abe7` — fix: add repository field to diagnostics package for
OIDC provenance
- #3309 — fix: publish releases with pnpm to resolve workspace and
catalog protocols (already on `main`, kept by 3-way merge)

## How CD will behave on merge

1. `lerna version --conventional-commits --conventional-graduate --yes`
graduates `4.1.0-dev.1` → `4.1.0`, creates tag `v4.1.0`, and pushes the
`[no ci] Release: 4.1.0` commit.
2. `pnpm release:verify` packs every public package and asserts no
`workspace:` / `catalog:` literal survives the pack step.
3. `pnpm -r publish --access public --no-git-checks` uploads the 8
public packages with all `workspace:*` / `catalog:` references rewritten
to concrete versions.

## Sanity checks already performed locally

- `git merge-tree` between `origin/main` and `origin/dev`: clean, no
conflicts.
- `pnpm install --frozen-lockfile` on the merged tree: no lockfile
drift.
- `pnpm release:verify` on `release/4.1.0`: all 8 public packages clean
at `4.1.0-dev.1` (the same manifests that will be bumped to `4.1.0`).

## Follow-ups (not blocking)

- Once `4.1.0` is on `latest`, consider `npm deprecate
@faststore/<pkg>@4.0.0 "Broken release: workspace:/catalog: not
resolved. Use 4.1.0+"` for `cli`, `core`, `api`, `ui`, `components`,
`sdk`, `diagnostics`, `lighthouse`.
- Optional: add `workflow_dispatch` to `release.yml` so future hotfix
releases without `packages/*` changes can be triggered manually with
`--force-publish`.

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Larícia Mota <[email protected]>
Co-authored-by: Matheus P. Silva <[email protected]>
Co-authored-by: Leandro Rodrigues <[email protected]>
Co-authored-by: vtexgithubbot <[email protected]>
Co-authored-by: Lucas Feijó <[email protected]>
Co-authored-by: Luiz Falcão <[email protected]>
Co-authored-by: Artur Santiago <[email protected]>
Co-authored-by: Sahan Jayawardana <[email protected]>
Co-authored-by: Mateus Pontes <[email protected]>
Co-authored-by: Matheus Martins <[email protected]>
Co-authored-by: renatomaurovtex <[email protected]>
Co-authored-by: Leandro Rodrigues <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Arthur Andrade <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Thiago Pereira <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Giuliana Rigaud <[email protected]>
Co-authored-by: renato <[email protected]>
Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: BrunaCubos <[email protected]>
Co-authored-by: Ícaro Oliveira <[email protected]>
Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Everton Ataide <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Otavio Moreira Meirelles <[email protected]>
Co-authored-by: Marco Cardoso <[email protected]>
Co-authored-by: Gabriel Paladino <[email protected]>
Co-authored-by: CodeRabbit <[email protected]>
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