Repository navigation
fix(api): preserve orderForm sales channel in validateCart - #3435
Conversation
Avoid wiping cart items after Quick Order by omitting stale session `sc` on the initial orderForm GET and adopting the orderForm SC when the cart etag is stale. Also defer client validateCart until the first validateSession completes.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe PR coordinates session validation with cart validation and adds VTEX sales-channel synchronization. Existing carts can preserve their sales channel, stale carts can adopt order-form channels, and returned carts can include the adopted channel. ChangesVTEX cart validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SessionValidation
participant CartValidation
participant VTEXOrderForm
participant SalesChannelState
SessionValidation->>CartValidation: complete session validation
CartValidation->>VTEXOrderForm: fetch order form with channel preservation
VTEXOrderForm-->>CartValidation: return order form and sales channel
CartValidation->>SalesChannelState: evaluate channel divergence
SalesChannelState-->>CartValidation: return adopted channel
CartValidation->>VTEXOrderForm: update cart using adopted channel
CartValidation-->>SessionValidation: silently synchronize session channel
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
|
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. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/api/src/platforms/vtex/resolvers/validateCart.ts (1)
381-448: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd resolver-level integration coverage for both sales-channel branches.
Add
*.int.test.tscases that invokevalidateCartand assert the initial Checkout URL, conditional refetch URL, and returned cart state for stale external carts and non-stale session-channel changes. The existingsalesChannelStaleFetchfixture only covers the catalog lookup.🤖 Prompt for 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. In `@packages/api/src/platforms/vtex/resolvers/validateCart.ts` around lines 381 - 448, Add resolver-level integration tests invoking validateCart for both stale external carts and non-stale session-channel changes. Assert the initial Checkout request URL, whether the conditional refetch occurs with the expected sales channel, and the returned cart state; do not rely solely on the salesChannelStaleFetch catalog fixture.Source: Coding guidelines
🤖 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/api/test/unit/platforms/vtex/clients/commerce.test.ts`:
- Around line 75-128: Rename the unit test file from commerce.test.ts to
index.test.ts and place it under the commerce directory so it matches the tested
source module commerce/index.ts and the required test-file naming convention.
Preserve the existing orderForm test contents unchanged.
In `@packages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.ts`:
- Line 45: Update the test around the JSON.parse call to explicitly throw when
result is null, allowing TypeScript to narrow it to a string before parsing;
remove the result as string assertion while preserving the existing object
match.
---
Nitpick comments:
In `@packages/api/src/platforms/vtex/resolvers/validateCart.ts`:
- Around line 381-448: Add resolver-level integration tests invoking
validateCart for both stale external carts and non-stale session-channel
changes. Assert the initial Checkout request URL, whether the conditional
refetch occurs with the expected sales channel, and the returned cart state; do
not rely solely on the salesChannelStaleFetch catalog fixture.
🪄 Autofix
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: 61dd66c4-c837-4178-b095-8bdcf9e8fbb5
📒 Files selected for processing (8)
packages/api/src/platforms/vtex/clients/commerce/index.tspackages/api/src/platforms/vtex/resolvers/validateCart.tspackages/api/src/platforms/vtex/utils/cartSalesChannel.tspackages/api/test/mocks/ValidateCartMutation.tspackages/api/test/unit/platforms/vtex/clients/commerce.test.tspackages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.tspackages/core/src/sdk/cart/index.tspackages/core/src/sdk/session/index.ts
Align the unit test path with the commerce/index.ts source module.
Extract SC adoption glue to reduce cognitive complexity, flatten nested template literals in checkout.orderForm, and narrow the cartSalesChannel test without a type assertion.
Extract the session-wait helper so unit tests can exercise immediate, subscribe, race, and timeout paths under the Quality Gate threshold.
There was a problem hiding this comment.
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/test/sdk/cart/waitForSessionValidated.test.ts`:
- Around line 31-43: Update both Store<boolean> mocks used by
waitForSessionValidated to include the required readInitial method, returning
the mock store’s initial boolean value consistently with read. Keep the existing
subscribe, unsubscribe, and set behavior unchanged.
🪄 Autofix
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: d1bd220b-92d0-4189-84b6-dcda5026716f
📒 Files selected for processing (3)
packages/core/src/sdk/cart/index.tspackages/core/src/sdk/cart/waitForSessionValidated.tspackages/core/test/sdk/cart/waitForSessionValidated.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/sdk/cart/index.ts
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
renatomaurovtex
left a comment
There was a problem hiding this comment.
Reviewed the full resolver flow on the head commit, plus the SDK store internals that the new client-side wait relies on. The design is sound: preserve the orderForm's SC on the first GET, let the orderForm win when the cart is externally stale, let the session win otherwise. Verified that the session↔cart import cycle is pre-existing (session/index.ts already imported cartStore) and the new hasValidatedSessionStore import is only dereferenced at call time, so module init order is safe. Also verified the 3s wait is effectively a safety net only: persisted always calls store.set() on IDB hydration and optimistic validates on every set, so validateSession fires on every page load and hasValidatedSessionStore flips quickly.
One scenario I couldn't convince myself is covered:
packages/api/src/platforms/vtex/resolvers/validateCart.ts
🟠 Persistent session↔orderForm SC divergence re-drops the items one request later. The stale-etag pass adopts the orderForm SC only into the request-scoped context (mutateChannelContext), then setOrderFormEtag makes the cart non-stale. If the client session never converges to the orderForm SC — validateSession derives it from Session Manager (store?.channel?.value ?? channel.salesChannel), so this happens whenever the external flow advanced the orderForm but not vtex_session — the next validateCart takes the non-stale path, shouldRefetchOrderFormWithSessionSalesChannel sees session 1 ≠ orderForm 4, and re-fetches with sc=1: Checkout recalculates under the stale session SC and drops the SC-4-only items. That's the original bug, deferred by one request.
Two asks:
- Confirm the Quick Order flow propagates its SC into Session Manager (
store.channel) — if yes, this is a non-issue for SO-641 and the divergence refetch only fires for genuine in-session switches. - Either way, add a repro step to "How to test it": reload twice after returning from Quick Order. The current steps only prove the first validation.
If Session Manager does not converge, consider gating the refetch on an SC change observed in-session (e.g. channel actually mutated since the last validation) instead of any divergence.
🟡 No resolver-level test for the new branches. The pure helpers are well covered, but nothing asserts that validateCart actually issues the second GET with sc on divergence, or that the adopted channel reaches mutateChannelContext on the stale path. A mutations.test.ts case with session SC ≠ orderForm SC (non-stale) asserting the second fetch URL would lock the behavior against refactors.
💬 adoptOrderFormSalesChannelIfNeeded(ctx, orderForm, isStale) is only called inside if (isStale), so the third parameter is always true — the helper's re-check is dead in practice. Fine to keep for the pure-function test surface, but the call site could drop the flag.
packages/core/src/sdk/cart/waitForSessionValidated.ts
The read → subscribe → re-read race handling is correct, and resolving on timeout (rather than rejecting) is the right degradation. Nice test coverage, including the between-read-and-subscribe race.
Verdict: Approved with comments
Blocking (🔴/🟠):
- 🟠 Answer the two-request divergence question above (and add the double-reload repro step) before merge — if Session Manager doesn't carry the external SC, this reintroduces SO-641 one request later.
Non-blocking (🟡/💬):
- 🟡 Resolver-level integration test for the divergence refetch / SC adoption.
- 💬 Redundant
isStaleparam at the adoption call site.
Checks to confirm before merge: pnpm turbo run test --filter=@faststore/api --filter=@faststore/core · build · pnpm size (core/sdk touched)
|
Reviewed the full 1. The new core test file doesn't type-checkBoth hand-rolled Vitest passes because it strips types instead of checking them, and CI stays green because no workflow runs 2. The session likely won't converge to the orderForm SC, so a second
|
Stop refetching Checkout with a lagging session SC on later validations, which wiped Quick Order items one request after the first preserve/adopt. Expose optional StoreOrder.salesChannel when SC was adopted from a stale cart.
Keep Checkout on the orderForm trade policy when session SC lags, return the adopted SC from validateCart, and silently align fs::session so later requests use the correct channel without revalidating the cart mid-flight.
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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/api/test/integration/mutations.test.ts`:
- Around line 194-298: Move the two validateCart integration tests around the
divergent and stale sales-channel scenarios from mutations.test.ts into a new
validateCart.int.test.ts file. Preserve their setup, mocks, assertions, and
required imports so pnpm test:int discovers them, while keeping
mutations.test.ts for unit tests only.
- Around line 169-180: Update withOrderFormSalesChannel to return the widened
object shape produced after replacing result, rather than claiming the original
generic subtype T; preserve the generic input constraint and merged fields.
Rename the test file from mutations.test.ts to mutations.int.test.ts to match
the integration-test naming convention.
In `@packages/core/src/sdk/session/syncSalesChannelFromOrderForm.ts`:
- Around line 23-29: Update the channel parsing in syncSalesChannelFromOrderForm
so parsed values are accepted only when they are non-null objects; otherwise
reset channel to an empty record before the salesChannel comparison. Add
coverage for valid non-object JSON, including null, and preserve the existing
comparison behavior for valid channel objects.
In `@packages/core/test/sdk/session/syncSalesChannelFromOrderForm.test.ts`:
- Around line 5-16: Update the baseSession fixture to return a complete Session
object by supplying every required Session field, then remove the `as Session`
type assertion. Keep the existing salesChannel, currency, locale, country,
channel, and person values unchanged while relying on TypeScript to validate the
fixture and expose future Session contract changes.
🪄 Autofix
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: 478e3803-6bde-4b4f-90cf-6afacb846511
⛔ Files ignored due to path filters (4)
packages/api/src/__generated__/schema.tsis excluded by!**/__generated__/**and included bypackages/**packages/api/test/integration/__snapshots__/mutations.test.ts.snapis excluded by!**/*.snapand included bypackages/**packages/core/@generated/gql.tsis excluded by!**/@generated/**,!**/@generated/**and included bypackages/**packages/core/@generated/graphql.tsis excluded by!**/@generated/**,!**/@generated/**and included bypackages/**
📒 Files selected for processing (14)
packages/api/src/platforms/vtex/clients/commerce/index.tspackages/api/src/platforms/vtex/resolvers/validateCart.tspackages/api/src/platforms/vtex/resolvers/validateSession.tspackages/api/src/platforms/vtex/typeDefs/order.graphqlpackages/api/src/platforms/vtex/utils/cartSalesChannel.tspackages/api/test/integration/mutations.test.tspackages/api/test/mocks/ValidateCartMutation.tspackages/api/test/unit/platforms/vtex/utils/cartSalesChannel.test.tspackages/core/src/sdk/cart/index.tspackages/core/src/sdk/cart/waitForSessionValidated.tspackages/core/src/sdk/session/index.tspackages/core/src/sdk/session/syncSalesChannelFromOrderForm.tspackages/core/test/sdk/cart/waitForSessionValidated.test.tspackages/core/test/sdk/session/syncSalesChannelFromOrderForm.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/api/test/mocks/ValidateCartMutation.ts
- packages/api/src/platforms/vtex/clients/commerce/index.ts
- packages/core/test/sdk/cart/waitForSessionValidated.test.ts
- packages/core/src/sdk/cart/waitForSessionValidated.ts
- packages/core/src/sdk/session/index.ts
Lower validateCart/validateSession cognitive complexity, guard non-object channel JSON before syncing adopted SC, and add coverage for the new paths.
Extract session helpers into a dedicated util and add unit tests so the validateSession refactor no longer tanks Coverage on New Code.
|
## What's the purpose of this pull request? Since 4.6.0 ([#3435](#3435)), stores whose sales channel is not `1` can lose every product on shelves, PLPs and PDPs for **anonymous visitors** ([SO-685]). The fix for the Quick Order case ([SO-641]) still holds. **Root cause (checked against the Checkout API on two accounts):** Checkout only stores an SC on the orderForm after an **items mutation sent with `sc`**. `validateCart` fetches existing orderForms without `sc`. For an orderForm that never had items, Checkout then answers with the platform default, **SC 1** (as documented in vtex.js for Checkout). FastStore: 1. adopted SC 1 for an empty cart and returned `order.salesChannel = "1"`; 2. wrote it to `fs::session` with `hasOnlyDefaultSalesChannel: false`; 3. treated that flag as a permanent pin in `validateSession`. `validateSession` itself writes `false` for almost every shopper, so Session Manager was ignored from then on. On the affected store, SC 1 is access-restricted. Every product query returned 401/400 and the session never recovered: Session Manager answers `sc=1` with 401, and that error was swallowed. | orderForm state | request without `sc` | SC returned | |---|---|---| | never had items | `refreshOutdatedData=false/true` | **1** (default) | | item added with `sc=X` | `refreshOutdatedData=true` | **X**, item kept | | had items, then emptied | `refreshOutdatedData=true` | **X** | ## How it works? **`@faststore/api`** - `validateCart`: the SC returned by the SC-less fetch is trusted only when the orderForm has items or already matches the session SC (`shouldTrustOrderFormSalesChannel`). Otherwise the orderForm is refetched with `sc=<session SC>`. This runs before `isOrderFormStale`. The orderForm SC is adopted only when the orderForm has items, which keeps the Quick Order fix. - New `salesChannelSource` marker, stored only in the raw `channel` JSON string. The public `Channel` / `GraphqlContext` types and the GraphQL schema do not change: - `orderForm`: set after an adoption. `validateSession` keeps the client SC and re-emits the marker. - `url`: set by localization. `validateCart` always sends `sc` and never adopts. `validateSession` keeps the SC. - no marker: Session Manager's `store.channel` wins again, and `hasOnlyDefaultSalesChannel` is back to its pre-4.6 meaning (`!store.channel`). - `validateSession`: if Session Manager rejects the requested `sc` (401/403), the call is retried once without `sc` (except for the `url` marker). Sessions stuck on a restricted SC heal this way. - When the rejected SC was adopted from the orderForm (`orderForm` marker), the marker is dropped and the SC is recorded as `rejectedSalesChannel`. `validateCart` does not trust or adopt that SC again and refetches the orderForm with the session SC, so adoption and rejection cannot loop. The cart is then priced on an SC the shopper can use (items only sold on the rejected SC become unavailable, as in ≤ 4.5). - Found while testing on the affected account: an item added on an SC that is restricted for anonymous shoppers kept the storefront on that SC and product queries returned 400. With this change the session goes back to the store SC, the item stays in the cart and product queries return 200. - `validateSession` also heals sessions pinned to the SC 1 fallback on stores where SC 1 is public (Session Manager would confirm `sc=1`, so there is no 401 to trigger the retry). When an unmarked session is on SC 1, the URL has no `?sc=` and the store SC is not 1, it requests the store SC instead. If Session Manager assigns SC 1 on purpose, it still answers SC 1. - A recorded rejection is scoped: it is only recorded when the rejected `sc` is the adopted SC (a rejected `?sc=` from the page URL keeps the adoption), and it is forgotten when the shopper logs in or out. **`@faststore/core`** - `syncSalesChannelFromOrderForm` tags adopted channels with `salesChannelSource: 'orderForm'`. `releaseAdoptedSalesChannel` drops the tag once the validated cart is empty. `syncSessionWithValidatedCart` wires both into `validateCart`. - Localization (`getInitialSession`, `reconcileSessionLocale`, `useLocalizationConfig`) tags URL-derived channels with `salesChannelSource: 'url'`. - `filterChannel` strips the marker and `rejectedSalesChannel`, so they never reach catalog queries or cache keys. `releaseAdoptedSalesChannel` also drops `rejectedSalesChannel` once the cart is empty. - Region flows (`useRegion`, used by `RegionModal`/`RegionPopover`/`RegionSlider`) validate a new postal code with the stored channel, not the filtered one from `useSession()`, so setting a region keeps the markers. **Behavior changes to note** - **SC precedence for sessions without a `salesChannelSource` marker** (intentional; the unit test that pinned the old behavior was updated): | Version | Client channel with `hasOnlyDefaultSalesChannel: false`, Session Manager returns another `store.channel` | |---|---| | ≤ 4.5 | Session Manager wins | | 4.6–4.9 | Client SC wins, forever. `validateSession` writes `false` for almost every shopper, so this pinned virtually everyone, including sessions moved to SC 1 by SO-685 | | This PR | Session Manager wins (≤ 4.5 behavior). Only an explicit marker (`orderForm` after an adoption, `url` for localization) keeps the client SC | Legacy sessions persisted by 4.6–4.9 carry the flag but no marker, so they follow Session Manager on the next validation. This is how stuck sessions heal. - On localization stores, the URL SC always wins. Known limitations there: - an SC set externally (e.g. Quick Order) is not adopted; - an SC that Session Manager assigns (shopper profile / B2B) is not applied. In 4.6–4.9 it applied on the first validation and `reconcileSessionLocale` overwrote it on the next IDB read; this PR removes that window. A real fix needs a way to tell a profile SC from an echoed `sc`, plus a change to `reconcileSessionLocale`, so it is out of scope here. - Cost: one extra Checkout GET, only for existing **empty** orderForms whose SC-less fetch diverges from the session. This runs client-side, after hydration. ## How to test it? - `cd packages/api && pnpm test`: all 413 tests pass. New cases are in `test/integration/mutations.test.ts` ("sales channel of empty orderForms (SO-685)"), `validateSession.test.ts`, `sessionChannel.test.ts` and `cartSalesChannel.test.ts`. - `cd packages/core && pnpm vitest run test/sdk test/utils/filterChannel.test.ts`: all pass. - Manual, on a store whose SC ≠ 1: 1. Open a PDP in an incognito window. The second `ValidateCartMutation` must not return `salesChannel`, and product queries keep the store SC. 2. Seed `fs::session` with `{"salesChannel":"1","hasOnlyDefaultSalesChannel":false}` and reload. The session heals to the store SC. - SO-641 regression: force a different session SC, add an SC-only SKU through the Cart API with `sc`, then reload. The item stays and `order.salesChannel` is returned. Note: locally, 3 tests in `packages/core/test/utils/cookieCacheBusting.test.ts` fail with and without this change (unrelated, likely Node 25's built-in `localStorage`). ### Validation on real accounts Ran `@faststore/core` from this branch locally against three accounts (production Checkout and Session Manager; CMS from `storeframework` where the account had no content): | Account | Scenario | Result | |---|---|---| | Affected store (no localization, SC 4, SC 1 restricted) | Baseline 4.9.0 | Bug reproduced: session stuck on SC 1, Session Manager 401 for `sc=1` | | | Anonymous visitor | Stays on SC 4, no `order.salesChannel`, no loop | | | Session stuck on SC 1 (4.6–4.9 shape) | Heals to SC 4 (401 → retry without `sc`) | | | Item added on another SC outside FastStore | SC adopted with the `orderForm` marker, item kept | | | Adopted SC rejected by Session Manager | Back to SC 4 with `rejectedSalesChannel`, item kept, product queries 200 (were 400 before this case was handled) | | | Cart emptied | Marker released, session on the store SC | | `brandless` (localization, `/en-US` SC 1, `/pt-BR` SC 2, `/en-CA` SC 3) | Visitor on `/pt-BR` | SC 2 with `url` marker; marker not sent in catalog query variables | | | orderForm changed outside FastStore on SC 1 | Not adopted; cart moves to SC 2 | | | Switch to `/en-CA` with an item | Cart recalculated on SC 3; item not sold there removed with a message; no adoption back | | `b2bfaststoredev` (B2B + localization) | Logged-in B2B user with an active contract | Session Manager still returns SC 1, so the `url` marker limitation has no effect on this store | Not covered: an SC-exclusive SKU surviving the adoption (catalogs were identical across SCs; the SO-641 fix already covers it). Local tip: use `*.localhost`, not `127.0.0.1`. That host is not in the cookie domain allowlist, so Checkout cookies are dropped and each `validateCart` creates a new cart (pre-existing). ### Starters Deploy Preview Pending (CodeSandbox build for this PR). ## References - [SO-685]: products disappear after `validateCart` moves the session to SC 1 - [SO-641]: cart emptied when returning from Quick Order - [#3435](#3435): origin of the regression - [vtex.js for Checkout](https://developers.vtex.com/docs/guides/vtexjs-for-checkout) (`salesChannel` default = 1), [Session data available from VTEX apps](https://developers.vtex.com/docs/guides/session-data-available-from-vtex-apps) (401/403 for unavailable `sc`) [SO-685]: https://vtex-dev.atlassian.net/browse/SO-685 [SO-641]: https://vtex-dev.atlassian.net/browse/SO-641 ## Checklist - [x] PR title and commit messages follow Conventional Commits - [ ] Added a label according to the PR goal (`bug`) - [x] No `pnpm-lock.yaml` changes 🤖 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** * Sales channels selected through the URL are preserved during cart validation and session updates. * Empty-cart validation no longer treats a sales channel adopted from a previous order form as an active adoption; carts with items continue to use their validated channel. * When a sales-channel request is rejected, the session retries without that channel when appropriate. Other failures do not trigger a retry. * Cart updates keep session sales-channel information in sync with the validated cart, including when validation returns no result. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>

0 New Issues
0 Fixed Issues
0 Accepted Issues
What's the purpose of this pull request?
After returning from Quick Order (or similar external checkout flows),
validateCartwas sending a stale sessionscon the orderForm GET. Checkout recalculated the cart under the wrong trade policy and dropped items only available in the orderForm's sales channel (e.g. SC 4). Tracked in SO-641 /#team-faststore.How it works?
API (
validateCart)preserveSalesChannel(omits?sc=) so Checkout keeps the cart's current sales channel.orderForm.salesChannelinto the GraphQL channel context.Core
validateCartuntil the firstvalidateSessioncompletes (3s timeout), reducing the race where cart validates with a stalesession.channel.Before / After
How to test it?
Preview URL (sandbox): https://sfj-119ced8--storeframework.preview.vtex.app
QA store PR: https://github.com/vtex-sites/faststoreqa.store/pull/907
cd packages/api && pnpm vitest run test/unit/platforms/vtex/utils/cartSalesChannel.test.ts test/unit/platforms/vtex/clients/commerce/index.test.tscd packages/core && pnpm vitest run test/sdk/cart/waitForSessionValidated.test.tscd packages/api && pnpm vitest run test/integration/mutations.test.tsvalidateCartmust not wipe them.Starters Deploy Preview
References
Checklist
bug)pnpm-lock.yamlchangesMade with Cursor
Summary by CodeRabbit
Bug Fixes
Tests