[bug]: Infinite Reloading when magento cart id changes in storage #4241
Labels
bug
Something isn't working
issue: Cannot Reproduce
when issue not reproducible by internal team they might required additional info or steps missing
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
The text was updated successfully, but these errors were encountered: