magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.32k forks source link

Bug when Creating a Mixin on Magento_GoogleTagManager with AdBlocker enabled #34335

Closed leonhelmus closed 2 years ago

leonhelmus commented 3 years ago

Preconditions Magento 2.4.2 commerce edition mysql 8.0 php 7.4

Steps to reproduce

Expected result

Actual result Checkout is loading infinitely

Similar old issues https://github.com/magento/magento2/issues/12428

Technical Investigations This comment https://github.com/magento/magento2/issues/12428#issuecomment-416556613 is suggesting to replace with the old resolver, where the pending check was changed, while this seems to work but we believe it is not the best solution.

the problem is with isRejected function

    function isRejected(module) {
        return registry[module.id] && (registry[module.id].inited || registry[module.id].error);
    }

As we can see, it is checking the registry for the module id, when this condition is checked for the mixins, it is not returning true since .inited is always null, while for the original module it is returning true as expected.

for example when this condition is called for this module id ‘Magento_GoogleTagManager/js/google-tag-manager-cart’ it is returning true, while for the mixins ‘mixins!Magento_GoogleTagManager/js/google-tag-manager-cart’ it is returning false although we expect if the module is rejected the same should be for its mixins.

as a hotfix we tried the following and it worked:

    function isRejected(module) {
        return registry[module.id] && (registry[module.id].inited || registry[module.id].error || (registry[module.name] && registry[module.name].inited));
    }

this is because for mixins module.name is identical to the id of the parent module, similarly, we could just check for the module id after removing mixins! from the beginning.

Special thanks to omarmohssen for investigating.

m2-assistant[bot] commented 3 years ago

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

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


: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

mrtuvn commented 3 years ago

Do you check the case define mixin in requirejs-config ? Instead of use mixins!Magento_GoogleTagManager/js/google-tag-manager-cart Does it work same

leonhelmus commented 3 years ago

@mrtuvn i have not tried that. We've tried a lot of ways to get this working, but at the end we couldn't do anything except overwrite the whole thing with a map override... could you give an example in a code note on what your approach would be? Than i can try it myself.

mrtuvn commented 3 years ago

Normal way magento can define mixin explicit in file requirejs-config https://devdocs.magento.com/guides/v2.4/javascript-dev-guide/javascript/js_mixins.html I'm not tested with the case enable plugin AdBlock but sometimes magento not call mixin correct as we expected. Due race-condition problem and network condition. When magento call and init origin component js before that mixins defined. So problem may happen.

You also can call mixin like this

define([
    'mixins!ComponentJsPath'
], function () {
    'use strict';

    return function (originComponent) {
        //CODE HERE SOMETIMES NOT REACH
    };
});

OR following like this

var config = {
config: {
    mixins: {
        'Magento_Checkout/js/action/place-order': {
            'CustomModule/js/order/place-order-mixin': true
        },
        'Magento_Checkout/js/action/set-payment-information': {
            'CustomModule/js/order/set-payment-information-mixin': true
        }
    }
}
};

Can you provide more details of your store for easier to someone else able reproduce issue ? Do you use Minify js Bundle js (origin magento or 3rd-party implement) Merge js

engcom-November commented 2 years ago

Hi @leonhelmus , We are closing this issue as there has been no latest update on the same. Thank you.