Closed HenKun closed 2 years ago
Hello @HenKun , thank you for the detailed report! We have seen this issue recently, mostly on pages where multiple Amazon Pay buttons are rendered. We have a patch available:
amazon-button-render.patch.txt
(You can remove the .txt extension before applying the patch.) This fix should be included in an upcoming release, TBD. Please let us know if you are able to apply this successfully with positive results!
@sgabhart22 Thanks for the patch.
Yes, there is the Amazon Sign In button rendered additionally on the page. But no second Pay button. As far as I can see this "fix" only catches the error, logs and returns. Is there more about the patch?
@HenKun Not much more about the patch, it's really just preventing the stoppage of execution when the initial button container isn't found, allowing the rendering to complete successfully. We are also planning to include this error handling in the next release as well.
Ah I see, so when the initial button rendering fails (and the exception is catched) then the button is rendered again later on successfully? That would indeed solve the issue so far,
What I expected
The Amazon Pay Button is shown in minicart correctly
What happened instead
Sometimes the button does not show up in minicart, emitting the console error:
This mostly happens when the first item is added to the cart. When adding more items, or when reloading the page with a filled cart, the button seems to render flawlessly.
As follows, the HTML code of the button when it renders vs. when it does not render.
Correct (rendered):
Error case - not rendered:
Note, how
$buttonRoot
is neither emptied nor having the newly generated unique id added, at the time the error occurs. So I suspect there is still a race condition between adding the button container to the DOM and evaluating the unique id in APay checkout.js. I am by far no JS expert, but I think while the button container is created by knockout, it is not yet added to the DOM when the unique id is added. This is different when there are already items in the cart, since the minicart is fully rendered at page load.Note that there already was a similar issue in a former version: https://github.com/amzn/amazon-payments-magento-2-plugin/issues/1052
Steps to reproduce the issue
Your setup