Skip to content

fix: Avoid duplicate SKU selectors when changing locale#3264

Open
hellofanny wants to merge 1 commit intocanary-v2from
fix/duplicate-SKUselectors-localized
Open

fix: Avoid duplicate SKU selectors when changing locale#3264
hellofanny wants to merge 1 commit intocanary-v2from
fix/duplicate-SKUselectors-localized

Conversation

@hellofanny
Copy link
Copy Markdown
Contributor

@hellofanny hellofanny commented Apr 9, 2026

What's the purpose of this pull request?

This PR attempts to fix the duplicate SKU selectors when switching the locales.

before after
image image

How it works?

mergePdpData uses deepmerge with overwriteMerge for arrays, then overrides product.isVariantOf.skuVariants with the client payload when the client sends skuVariants. That way localized keys in availableVariations are not accumulated across server and client; the client’s skuVariants wins and the UI renders a single selector block.

How to test it?

  • Run the project locally, enabling the localization feature as explained here
  • Open the Nike Men's Air Max 1 G Spikeless Golf Shoes PDP
  • Switch the locale to pt-BR or it-IT
  • It should display one sku selector according to the current locale.
sku-selector-no-duplication.mov

Starters Deploy Preview

preview link
PR

References

https://vtex-dev.atlassian.net/browse/SFS-3094?atlOrigin=eyJpIjoiYjZmYWFkNTJhYWU2NDA5MzgxNTcyMzBjMzgwYmNlMDMiLCJwIjoiaiJ9

Summary by CodeRabbit

  • Bug Fixes
    • Improved product variant data handling to ensure correct merging of SKU information from multiple sources.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Walkthrough

This change extracts the product data merging logic in a PDP page into a dedicated mergePdpData helper function and adds conditional handling for client-side SKU variant overwriting.

Changes

Cohort / File(s) Summary
Product Data Merging
packages/core/src/pages/[slug]/p.tsx
Replaced inline deepmerge call with mergePdpData helper that performs base merge and conditionally overwrites skuVariants with client data. Added typed import for ClientProductQueryQuery.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • eduardoformiga
  • lucasfp13

Poem

🧬 A merge that once stood alone,
Now nested in a helper's home,
SKU variants dance with grace,
In FastStore's product space! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preventing duplicate SKU selectors when locale changes, which directly addresses the changeset's core purpose of overriding skuVariants.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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/duplicate-SKUselectors-localized

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
Copy link
Copy Markdown

codesandbox-ci bot commented Apr 9, 2026

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.

@hellofanny hellofanny changed the title fix: Updates skuVariants from client fix: Avoid duplicate SKU selectors when changing locale Apr 9, 2026
@hellofanny hellofanny marked this pull request as ready for review April 9, 2026 14:04
@hellofanny hellofanny requested a review from a team as a code owner April 9, 2026 14:04
@hellofanny hellofanny requested review from eduardoformiga and renatomaurovtex and removed request for a team April 9, 2026 14:04
@hellofanny hellofanny self-assigned this Apr 9, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core/src/pages/[slug]/p.tsx (1)

96-102: Simplify type safety by removing unnecessary casts in mergePdpData.

The function accepts client: Partial<ClientProductQueryQuery> | Record<string, unknown> | undefined, but casts it to ServerProductQueryQuery for deepmerge, then immediately re-casts it back to extract skuVariants. Instead, define client with a narrower type (e.g., Partial<ClientProductQueryQuery> | undefined) to eliminate both as assertions and keep the path fully typed without type widening.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/pages/`[slug]/p.tsx around lines 96 - 102, The code widens
`client` then uses unsafe casts in mergePdpData; change the `client` parameter
type from `Partial<ClientProductQueryQuery> | Record<string, unknown> |
undefined` to a narrower `Partial<ClientProductQueryQuery> | undefined`, remove
the `as ServerProductQueryQuery` cast passed into `deepmerge` and the subsequent
`as Partial<ClientProductQueryQuery>` cast when computing `clientSkuVariants`,
and ensure `deepmerge(server, client ?? {}, { arrayMerge: overwriteMerge })` and
the `client?.product?.isVariantOf?.skuVariants` access use the properly typed
`client` so no type assertions are needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/core/src/pages/`[slug]/p.tsx:
- Around line 96-102: The code widens `client` then uses unsafe casts in
mergePdpData; change the `client` parameter type from
`Partial<ClientProductQueryQuery> | Record<string, unknown> | undefined` to a
narrower `Partial<ClientProductQueryQuery> | undefined`, remove the `as
ServerProductQueryQuery` cast passed into `deepmerge` and the subsequent `as
Partial<ClientProductQueryQuery>` cast when computing `clientSkuVariants`, and
ensure `deepmerge(server, client ?? {}, { arrayMerge: overwriteMerge })` and the
`client?.product?.isVariantOf?.skuVariants` access use the properly typed
`client` so no type assertions are needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ac8279a1-f1dd-4d18-b3a3-e8142e0c2509

📥 Commits

Reviewing files that changed from the base of the PR and between 0070f89 and 7c17058.

📒 Files selected for processing (1)
  • packages/core/src/pages/[slug]/p.tsx

@hellofanny hellofanny requested a review from lemagnetic April 10, 2026 20:03
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.

1 participant