Closed MichaelHeinzman closed 4 months ago
Hi @MichaelHeinzman. 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.
Infinite Reloading when magento cart id changes in storage Hi, As per testing the issue, we are not able to reproduce it and also using @magento/peregrine:version: 13.2.1. kindly suggest if we are missing any steps to reproduce the same Steps we tried-:
Expected: all pages reloads but not infinite Attaching the vedio for the same Thank You
https://github.com/magento/pwa-studio/assets/143005735/8bee83ea-770b-4e29-94b4-1702eef3ed67
Hi @MichaelHeinzman As its is more than 2 weeks, so we are closing this issue. If you have further any issue with this ticket.Please free to discuss with us. Thank You
Describe the bug When multiple tabs are open our site was receiving infinite reloads after changing the magento cart id in storage. This was after upgrading from version 11 to 12.4.0 of magento peregrine. Which makes sense, since the useEventListener to reload the page when cart id changes was added to cart.js in 12.1.0.
This may be a specific case for our site, but I believe it's something we only ran into because of how the storage listener and the reload when cart id changes was handled.
When a change is detected, it reloads the page which is correct behavior. However, reloading doesn't cause the useEventListener hook to remove it's event listener. Once I added a line to remove the event listener before reloading, it stopped the infinite reloads. To fix this in our site I had to create a custom cart.js and PeregrineContextProvider to make the change.
I believe react doesn't have a chance to run the code in the return statement of useEventListener in the useEffect.
Expected behavior Reloads once after cart change but not infinitely.
Possible solutions
Removing event listener before the reload.
OR
Removing event listener using beforeunmount in the useEventListener hook so that it guarantees it runs on reloads.
peregrine