magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

JS error in console on checkout when recaptcha for checkout/placing order is not enabled

Open basvanpoppel opened this issue 5 years ago • 38 comments

Preconditions (*)

  1. Magento 2.4.3
  2. 'Stores > Configuration > Security > Google reCAPTCHA Storefront > Storefront > Enable for Checkout/Placing Order' set to 'No' (that's the default config)

Steps to reproduce (*)

  1. Add a product to cart
  2. Go to checkout
  3. Open element inspector, see the JS error

Expected result (*)

  1. No JS errors on checkout
  2. Besides not wanting to run into errors, I wouldn't expect checkout to load any recaptcha JS when all the recaptcha options are not enabled.

Actual result (*)

  1. Error message from recaptcha JS:
knockout.js:3753 Uncaught TypeError: Unable to process binding "afterRender: function(){return renderReCaptcha() }"
Message: Cannot read property 'rendering' of undefined
    at UiClass.initCaptcha (reCaptcha.js:117)
    at UiClass.renderReCaptcha (reCaptcha.js:182)
    at afterRender (eval at createBindingsStringEvaluator (knockout.js:3221), <anonymous>:3:134)
    at init (after-render.js:17)
    at knockout.js:3730
    at Object.ignore (knockout.js:1563)
    at knockout.js:3729
    at Object.arrayForEach (knockout.js:168)
    at applyBindingsToNodeInternal (knockout.js:3715)
    at applyBindingsToNodeAndDescendantsInternal (knockout.js:3573)

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [x] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

ps. I think severity should be higher, because any dev working om checkout will spot this, and will be looking for a fix. (I first checked all of my modules, themes and 3rd party modules: it's time consuming.)

basvanpoppel avatar Aug 10 '21 20:08 basvanpoppel

Hi @basvanpoppel. Thank you for your report. To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar Aug 10 '21 20:08 m2-assistant[bot]

Can you proceed checkout with this js error?

mrtuvn avatar Aug 11 '21 00:08 mrtuvn

Not actually blocker but turn out even you not enable settings (Set NO) but code base still check it by default

mrtuvn avatar Aug 11 '21 01:08 mrtuvn

bug reported too fast :)

onlinebizsoft avatar Aug 11 '21 02:08 onlinebizsoft

:white_check_mark: Confirmed by @mrtuvn Thank you for verifying the issue. Based on the provided information internal tickets MC-43053 were created

Issue Available: @mrtuvn, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

magento-engcom-team avatar Aug 11 '21 03:08 magento-engcom-team

Hi @basvanpoppel Is P3 priority correct for such case ?

mrtuvn avatar Aug 11 '21 03:08 mrtuvn

Component: Recaptcha

mrtuvn avatar Aug 11 '21 03:08 mrtuvn

Hi @mrtuvn I would give it P2: Checkout doesn't break (the recaptcha component isn't used, so the JS error doesn't actually hurt) it's not critical and no work-around is needed, which follows P3 description.

But this is awful for developers working on checkout: I have several custom ui components, layout processors and mixins on any checkout i work on. If there's an issue after upgrading, I will first look at my customisations, then at third party modules, then Magento.

Imagine every dev going through this process after seeing this issue, that's a lot of wasted time - and a lot of unhappy devs.

basvanpoppel avatar Aug 11 '21 06:08 basvanpoppel

I'm working on a PR for this.

basvanpoppel avatar Aug 11 '21 07:08 basvanpoppel

New version new bug. I would sugest to set it P1 or better P -100 !?!?!?!?! Facing the same probllem and it is ugly to have errors even if they do not break the checkout process.

My opinion Chequille

chequille avatar Aug 11 '21 19:08 chequille

In addition to this:

  • adds a global place order mixin . what this does is that even if functionality is not configured , mixins are added in all cases see : https://github.com/magento/magento2/issues/15967
  • mixin has a hardcoded dependency to Magento_ReCaptchaWebapiUi not mentioned in module.xml that extension itself adds a mixin to jquery .o0 see: https://github.com/magento/magento2/issues/15967
  • adds a afterRender call to template forcing to init this functionality even if not configured or needed or each time the template is rendered , bad practice and hard UI dependency

speedupmate avatar Aug 16 '21 14:08 speedupmate

Hi @mrtuvn I would give it P2: Checkout doesn't break (the recaptcha component isn't used, so the JS error doesn't actually hurt) it's not critical and no work-around is needed, which follows P3 description.

@basvanpoppel ? install a clean instance of m2 you can't checkout cause of those issues without reCaptcha configuration being enabled and valid means Magento2 does not work out of the box.

By default if extension is in system and is not configured to be used should mean no assets are included in storefront at all. Aim for this in your PR, thanks.

speedupmate avatar Aug 16 '21 14:08 speedupmate

Fix for the impatient (Magento composer installations).

@basvanpoppel -this implements your suggested PR (https://github.com/magento/security-package/pull/302) changes :)

/patches/composer/github-issue-33741.diff

diff --git a/Block/LayoutProcessor/Checkout/Onepage.php b/Block/LayoutProcessor/Checkout/Onepage.php
index 390bf712..b2d5b777 100644
--- a/Block/LayoutProcessor/Checkout/Onepage.php
+++ b/Block/LayoutProcessor/Checkout/Onepage.php
@@ -79,7 +79,8 @@ class Onepage implements LayoutProcessorInterface
             ['place-order-recaptcha']['settings'] = $this->captchaUiConfigResolver->get($key);
         } else {
             if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
-                ['payment']['children']['beforeMethods']['children']['place-order-recaptcha'])) {
+                ['payment']['children']['beforeMethods']['children']['place-order-recaptcha-container']['children']
+                ['place-order-recaptcha'])) {
                 unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                     ['payment']['children']['beforeMethods']['children']['place-order-recaptcha-container']
                     ['children']['place-order-recaptcha']);
@@ -89,3 +90,4 @@ class Onepage implements LayoutProcessorInterface
         return $jsLayout;
     }
 }
+

/composer.json

{
(...)
    "extra": {
        (...)
        "patches": {
            (...)
            "magento/module-re-captcha-checkout": {
                "Fixed checkout reCaptcha disabling #33741": "patches/composer/github-issue-33741.diff"
            }
        }
    }
}

dudzio12 avatar Aug 16 '21 14:08 dudzio12

@basvanpoppel @dudzio12 although good effort it does not free you from all the loaded reCaptcha mixins defined in following files, those will still wrap what they wrap enabled/disabled layout nodes included or not

vendor/magento/module-re-captcha-paypal/view/frontend/requirejs-config.js 
vendor/magento/module-re-captcha-webapi-ui/view/frontend/requirejs-config.js
vendor/magento/module-re-captcha-frontend-ui/view/frontend/requirejs-config.js
vendor/magento/module-re-captcha-checkout/view/frontend/requirejs-config.js

it mostly means that even if recaptchas are not used your default behaviour is wrapped and no other module tests for those wrapped conditions and mostly assume that defaults are used

speedupmate avatar Aug 16 '21 14:08 speedupmate

@basvanpoppel That's understandable of course, I needed patch to kickstart my project's upgrades, so it is what it is.

I'm still looking forward for you to complete the PR :)

Then I will prepare another patch to fix the issue.

@mrtuvn What is the politics on P2 bug fixes? It will be released as separate patch, next patch release -p1 or in the next minor release?

dudzio12 avatar Aug 16 '21 15:08 dudzio12

p2 label is lower priority than p1/p0. It's depend on specific case of ticket. It's not related with fix order deliver to next release. i'm not sure magento team will deliver this fixes as patch (seperate) or regular fix as normal. I saw a pull request related in the case owner disabled captcha from backend but captcha js files still request from server. But we already have PR for that here Put here for anyone interesting https://github.com/magento/magento2/pull/33200. In this specific issue imho captcha js should only available if user put both user/key pair value in backend

mrtuvn avatar Aug 16 '21 15:08 mrtuvn

@mrtuvn this issue still has 'ready for dev' status, while this pr should be in the review process, I think: https://github.com/magento/security-package/pull/302

@speedupmate This PR just fixes this specific issue. Preventing other modules from adding wrappers isn't my goal here. If you know of a better way to fix this issue, please share it.

basvanpoppel avatar Aug 17 '21 20:08 basvanpoppel

@speedupmate This PR just fixes this specific issue. Preventing other modules from adding wrappers isn't my goal here. If you know of a better way to fix this issue, please share it.

Part of this is the layoutprocessor style config you are trying to add but with a plugin to requirejs-config collection class to just exclude non-configured extension files on matching conditions (like enabled/disabled , auth failing etc).

Even better would be stopping popularising mixins as a main go to weapon in devdocs for editing/wrapping component functionality as this is really a sledgehammer that affects wider scope than usual extension tries to cover.

speedupmate avatar Aug 18 '21 06:08 speedupmate

@speedupmate I think you haven't seen the PR, as I'm not adding config - i fixed a missing part in what's already there.

For the rest I totally agree with you.

basvanpoppel avatar Aug 18 '21 19:08 basvanpoppel

I am waiting for this fix. When it will be fixed ? What can I do in the meantime?

Hanhan1989 avatar Aug 20 '21 22:08 Hanhan1989