Skip to content

Fix cart items not visible on return visit until new item added#4586

Merged
del22123 merged 4 commits intomagento:developfrom
Niki-Tester:fix/cart-items-visibility-4585
Jan 20, 2026
Merged

Fix cart items not visible on return visit until new item added#4586
del22123 merged 4 commits intomagento:developfrom
Niki-Tester:fix/cart-items-visibility-4585

Conversation

@Niki-Tester
Copy link
Member

@Niki-Tester Niki-Tester commented Dec 15, 2025

Description

Added a useEffect hook to the CartContextProvider component that automatically loads the cart from localStorage when the component mounts. This ensures that when users return to the application after closing the tab or reloading the page, their previously added cart items are restored.

The effect checks if a cartId exists in localStorage, and if the Redux cartState is either empty or has a different cartId, it triggers asyncActions.getCartDetails() to fetch and restore the persisted cart data.

Related Issue

Closes #4585

Acceptance

Verification Stakeholders

Specification

Verification Steps

  1. Start with an empty cart
  2. Add one or more items to the cart (verify item is added and cartId is stored in localStorage)
  3. Reload the page
  4. Verify cart items are still visible and restored (no need to add another item to see them)
  5. Close the browser tab completely and reopen the application
  6. Verify cart items are still visible and restored

Test scenario(s) for direct fix/feature

Test scenario(s) for any existing impacted features/areas

Test scenario(s) for any Magento Backend Supported Configurations

Is Browser/Device testing needed?

Any ad-hoc/edge case scenarios that need to be considered?

Screenshots / Screen Captures (if appropriate)

Breaking Changes (if any)

Checklist

  • I have added tests to cover my changes, if necessary.
  • I have added translations for new strings, if necessary.
  • I have updated the documentation accordingly, if necessary.

- Add useEffect to load cart from localStorage on component mount
- When cardId exists in storage but Redux state is empty.different, trigger loadCart to restore persisted car items
- Fixes magento#4585
@pwa-studio-bot
Copy link
Collaborator

pwa-studio-bot commented Dec 15, 2025

Fails
🚫

node failed.

🚫

Cypress tests in the following files did not pass 😔. All tests must pass before this PR can be merged

  • displays assigned products:
    • AssertionError: Timed out retrying after 30000ms: Expected to find element: `[data-cy="CategoryContent-root"] [data-cy="GalleryItem-name"], [data-cy="SearchPage-root"] [data-cy="GalleryItem-name"]`, but never found it.
    ,shows products specific to the categories in the different store:
    • AssertionError: Timed out retrying after 30000ms: Expected to find element: `[data-cy="CategoryContent-root"] [data-cy="GalleryItem-name"], [data-cy="SearchPage-root"] [data-cy="GalleryItem-name"]`, but never found it.
    ,lets users add products to cart regardless of store view:
    • AssertionError: Timed out retrying after 30000ms: Expected to find element: `[data-cy="CategoryContent-root"] [data-cy="GalleryItem-root"]`, but never found it.

Log

ERROR ON TASK: cypressTests


Error:  Danger had errors running. See message(s) above for more details.
danger-results://tmp/danger-results.json

Generated by 🚫 dangerJS against 1f6546c

@pwa-studio-bot
Copy link
Collaborator

pwa-studio-bot commented Dec 15, 2025

Fails
🚫

node failed.

Log

ERROR ON TASK: cypressTests


Error:  Danger had errors running. See message(s) above for more details.
danger-results://tmp/danger-results.json

Generated by 🚫 dangerJS against 1f6546c

@pwa-studio-bot
Copy link
Collaborator

pwa-studio-bot commented Dec 15, 2025

Fails
🚫 A version label is required. A maintainer must add one.
Messages
📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next pr-test build run (assuming they are fixed).
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

Generated by 🚫 dangerJS against 1f6546c

@pwa-studio-bot
Copy link
Collaborator

Fails
🚫 Lighthouse assertions failed 😔. All assertions must pass before this PR can be merged
https://pr-4586.pwa-venia.com/

First Contentful Paint (maxNumericValue)

  • Expected: 2900
  • Actual: 2908.897
  • Result: Failed
  • Docs link: https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/
https://pr-4586.pwa-venia.com/valeria-two-layer-tank.html

First Contentful Paint (maxNumericValue)

  • Expected: 3200
  • Actual: 3201.343
  • Result: Failed
  • Docs link: https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/

Total Blocking Time (minScore)

  • Expected: 0.2
  • Actual: 0.17
  • Result: Failed
  • Docs link: https://developer.chrome.com/docs/lighthouse/performance/lighthouse-total-blocking-time/
🚫

node failed.

Log

Details

ERROR ON TASK: lighthouseTests


Error:  Danger had errors running. See message(s) above for more details.
danger-results://tmp/danger-results-6c02d85a.json

Generated by 🚫 dangerJS against 1f6546c

@del22123 del22123 merged commit b5746f9 into magento:develop Jan 20, 2026
6 of 13 checks passed
@Niki-Tester Niki-Tester deleted the fix/cart-items-visibility-4585 branch January 21, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: Cart items not visible on return visit until a new item is added

4 participants