[bug]: Stale cartId after guest user logs in
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:
- Open the website in a guest session (not logged in).
- Log in with a registered user account.
- Check the next GraphQl in the browser inspector: getItemCount, MiniCartQuery
- 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
https://github.com/user-attachments/assets/1a03c3db-7362-4da6-9903-6ea3472cc99d
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 - [x]
venia-ui - [ ]
pwa-buildpack - [x]
peregrine - [ ]
pwa-devdocs - [ ]
upward-js - [ ]
upward-spec - [ ]
create-pwa
Hi @joseamietta. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.
Add a comment to assign the issue: @magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
@magento I am working on this
@adobe export issue to Jira project PWA
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/PWA-3631 is successfully created for this GitHub issue.