Skip to content

jQuery Widget or UiComponent mixin don't loading or loading randomized #33593

Open
@denis-g

Description

@denis-g

Maybe need additional fixes on #25587 request.

Preconditions (*)

  1. Magento 2.4.x
  2. Google Chrome 92 (cache disabled on devtools)

Steps to reproduce (*)

  1. Fresh install m2 2.4.4 (also problem with all 2.4.x)
  2. Dev mode on
  3. Cache settings (all on, except for layout, block_html, full_page)
  4. Create new theme (luma parent)

theme structure

requirejs-config.js

var config = {
    map: {
        '*': {
            myWidget: 'Magento_Theme/js/my-widget'
        }
   },
   config: {
        mixins: {
            'Magento_Theme/js/my-widget': {
                'Magento_Theme/js/my-widget-mixin': true
            }
        }
    }
};

my-widget.js

define([
    'jquery',
    'jquery-ui-modules/widget'
], function ($) {
    'use strict';

    $.widget('mage.myWidget', {
        options: {
            color: 'red'
        },
        _create: function () {
            $('body').css('background-color', this.options.color);
        }
    });

    return $.mage.myWidget;
});

my-widget-mixin.js

define([
    'jquery',
    'jquery-ui-modules/widget'
], function ($) {
    'use strict';

    return function (widget) {
        $.widget('mage.myWidget', widget, {
            options: {
                color: 'green'
            }
        });

        return $.mage.myWidget;
    }
});

Expected result (*)

Mixin load and background is GREEN 🟢

Actual result (*)

Results depend on cache, opened devtools.

  1. Init widget on js file – mixin don't load (or randomized loading, also loading when devtools opened)
    Background is RED 🔴 or GREEN 🟢
define([
    'jquery',
    'myWidget'
], function ($, myWidget) {
    'use strict';

    myWidget();
});
  1. Init widget on phtml file – mixin don't load (or randomized loading, also loading when devtools opened)
    Background is RED 🔴 or GREEN 🟢
require([
    'jquery',
    'myWidget'
], function ($, myWidget) {
    'use strict';

    myWidget();
});
  1. Init widget on js file (with mage) – mixin load (or randomized don't loading)
    Background is GREEN 🟢 or RED 🔴
require([
    'jquery',
    'mage/mage'
], function ($) {
    'use strict';

    $('body').mage('myWidget', {});
});
  1. Init widget on js file (without alias) – mixin load (or randomized don't loading when devtools opened)
    Background is GREEN 🟢 or RED 🔴
define([
    'jquery',
    'Magento_Theme/js/my-widget'
], function ($, myWidget) {
    'use strict';

    myWidget();
});
  1. ALSO, when widget don't load and when call widget again (click event, etc) – mixin load
    Background is RED 🔴, after event is GREEN 🟢
require([
    'jquery',
    'myWidget'
], function ($, myWidget) {
    'use strict';

    myWidget();

    $('.action.mixin').on('click', function () {
        myWidget();
    });
});
  1. Init widget on phtml file with data-mage-initmixin load (works perfectly, without background flashing and mixin preloading)
    Background is GREEN 🟢
<div data-mage-init='{"myWidget": {}}'></div>
  1. Init widget on phtml file with js x-magento-initmixin load (works perfectly, without background flashing and mixin preloading)
    Background is GREEN 🟢
<script type="text/x-magento-init">
    {
        "*": {
            "myWidget": {}
        }
    }
</script>
  1. Init widget on js file (with mixins!) – mixin load (works perfectly, without background flashing and mixin preloading)
    Background is GREEN 🟢
define([
    'jquery',
    'mixins!myWidget'
], function ($, myWidget) {
    'use strict';

    myWidget();
});

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.
  • 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”.

Metadata

Metadata

Assignees

Labels

Area: UI FrameworkComponent: CacheIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S1Affects critical data or functionality and forces users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions