Skip to content

[bug]: Stale cartId after guest user logs in #4536

@joseamietta

Description

@joseamietta

Describe the bug

When a user browses the site as a guest and then logs in, several GraphQL calls are executed with a stale or old cartId, which leads to errors in the Magento logs.

To reproduce

Steps to reproduce the behavior:

  1. Open the website in a guest session (not logged in).
  2. Log in with a registered user account.
  3. Check the next GraphQl in the browser inspector: getItemCount, MiniCartQuery
  4. See the error: The current user cannot perform operations on cart ...

Expected behavior

Merge the guest's cart with the customer's cart and correctly replace the guest's cartId with the new customer's cartId for all subsequent GraphQL calls. And avoid dispatch request with a stale cartId.

Screenshots

Screencast.from.2025-08-14.09-22-20.mp4
Image

Possible solutions

Checking the talon useSignIn.js I can see that setToken is called before clear cart and customer data.
If setToken is moved after deleting that data the errors is not thrown.

Please complete the following device information:

  • Device [Notebook]:
  • Browser [Chrome]:
  • Browser Version [Version 138.0.7204.100 (Official Build) (64-bit)]:
  • Magento Version [Adobe Commerce 2.4.7-p6]:

Please let us know what packages this bug is in regards to:

  • venia-concept
  • venia-ui
  • pwa-buildpack
  • peregrine
  • pwa-devdocs
  • upward-js
  • upward-spec
  • create-pwa

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions