-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jQuery Widget or UiComponent mixin don't loading or loading randomized #33593
Comments
Hi @denis-g. Thank you for your report.
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:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 You can find the schedule on the Magento Community Calendar page. 📞 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. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
+1. We also randomly having similar issue. |
@ihor-sviziev yep. On bundle, merged, or single it doesn't matter. Core problem on matching mixin with widget/component and random apply. Also similar issue #22338 |
good call! Thanks you denis for some use-cases |
The reproduction path looks quite clear and I would start by attaching a logger/debugger in https://github.com/magento/magento2/blob/2.4-develop/lib/web/mage/requirejs/mixins.js#L161 to see if mixins are not loaded because they are not seen by the plugin or the whole mechanism is completely ignored. |
Hi @engcom-Delta. Thank you for working on this issue.
|
FYI we just tried to debug this issue - that's definitely a very random issue, and it looks like it is related to async js execution/script loading. When the issue reproducing, the following core return magento2/lib/web/mage/requirejs/mixins.js Line 161 in 97f0a1f
It looks like the issue coming from using wrapping (function() {
... requirejs-config.js content here
require.config(config);
})(); Or maybe it is related to magento2/lib/internal/Magento/Framework/RequireJs/Config.php Lines 79 to 85 in 7c6b636
So far, fixing this issue won't be really easy, so I stopped the research. BTW, if you'll try setting a breakpoint to that line, or even adding console.log - the issue won't reproduce OR will reproduce very-very rarely that makes debugging really hard. Summary: the issue happening because of the missing the I even thought it might be related to magento2/lib/web/mage/bootstrap.js Line 21 in 7c6b636
And, issue reproducing both with enabled and disabled PS: @krzksz, I think now is your turn. We need your knowledge and skills to resolve such hard frontend issues. |
Can we have or create new option allow developer determine when and how script defer or async ? Example if no specific we use async and if we specific <script type="text/x-magento-init" defer>
//Code
</script> Current magento only allow add defer tag script via xml. I think somewhere in the code collect and add this attribute. Can we have same approach for script in js or phtml ? |
@mrtuvn, as you see from the description, the case with |
https://github.com/magento/magento2/blob/2.4-develop/lib/web/requirejs/require.js#L1881 <= default we always have async true here. So basically all script loaded async will run as soon as it downloaded and may block parse html |
@mrtuvn, I'm pretty sure the issue isn't simple at all. |
Hi @engcom-Lima. Thank you for working on this issue.
|
@denis-g Your workaround 8. saved my day, but probably this should have a completely fix for all. |
Hi @denis-g, Thank you for reporting the issue with detailed description. Verified the issue on 2.4-develop and issue is reproducible. Here is what I did to reproduce:
Issue: In first 5 scenarios, result appeared first to be loaded with background RED that means mixin didn’t load properly but after reloading the page background became GREEN. So based on the above results, confirming the issue. |
Using your changes I made a module work. I noticed mixins form a marketplace module were never called and did not even show up in frontend. Came here after a google search. Module (free): https://marketplace.magento.com/sparsh-magento-2-order-comments-extension.html This module has two mixins:
With your changes to lib/web/mage/requirejs/resolver.js the mixins execute and the comment is saved to the order like expected, without your changes the comment is never saved to the order because the mixins will never execute. Between each test I cleared the static files. I have not yet tested if this change will affect anything else. |
Hi @denis-g, |
Hi @ihor-sviziev, On @Kemexyz mixin used a component. Is it probably a different func call there? 🤔 Or patch works with component only... Or something else affects. Additional testing is needed. Maybe someone has a working result with a patch? |
@mrtuvn, could you create a PR, so we'll be able to run all tests on top of these changes? |
faced the same issue with unapplied mixins on storefront. As mentioned previously, magento2/lib/web/mage/requirejs/mixins.js Line 139 in 4c36116
can't find mixins due to empty requirejs config. Seems like the issue introduced with this commit 540b134 After this changes, mixins use custom context of require, configured on first load of magento2/lib/web/mage/requirejs/mixins.js Lines 10 to 28 in 4c36116
One of possible solutions - change sequence of assets in head (swap magento2/app/code/Magento/RequireJs/Block/Html/Head/Config.php Lines 126 to 137 in 4c36116
Moreover, looks like this files should be swapped initially, because inserting using correct sequence, but mixed due to the same $requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
$assetCollection->insert(
$requireJsConfig->getFilePath(),
$requireJsConfig,
$after
);
$requireJsMixinsConfig = $this->fileManager->createRequireJsMixinsAsset();
$assetCollection->insert(
$requireJsMixinsConfig->getFilePath(),
$requireJsMixinsConfig,
$requireJsConfig->getFilePath() // <------ insert after $requireJsConfig asset
); |
The issue is reproducible only for target packages with changed path (using require Declaration of mixins var config = {
config: {
mixins: {
'myWidget': {
'Magento_Theme/js/my-widget-mixin': true
}
'Magento_Theme/js/my-widget': {
'Magento_Theme/js/my-widget-mixin': true
}
}
}
}; Using define([
'jquery',
'myWidget'
], function ($, myWidget) {
'use strict';
myWidget();
}); Short declaration will be used for |
@ihor-sviziev @mrtuvn Is there any update on this? |
@tuyennn sorry, I don't have any updates |
@ihor-sviziev @mrtuvn @isxam do we have a patch or workaround for this issue? I tried some of the solutions isxam provided such as specifying In our case, our custom mixins (which just override a widget function) were loading fine until we noticed a style tag in the HTML Head (through Magento's Scripts and Style Sheets CMS block) that referenced a non-existent stylesheet thus generating a 404. After removing that style tag the custom mixins stopped loading. I can only guess that the 404 was generating enough delay for the requirejs-config to be properly loaded and the mixins file to get its context, and without the 404 delay mixins do not get the requrejs-config. |
I have an instance on 2.4.7-p2 and this is happening with customer-data-mixin (and possibly others). How I am replicated it:
I am dumping requirejs contexts out right before my error is occurring, and I DO see the mixin defined and accessible as an object with methods available. However the storage property the mixin instantiates via call to originalFn customer-data is undefined. I have to debug further, but seems like the mixin is running after it is defined to requirejs and requirejs fires function off before mixin actually is parsed? |
Upon further debugging it appears any require call in the document can happen before the require mixin call, but after the define call due to setTimeout in requirejs allowing document to then be parsed. requirejs/mixins.js was loaded and being defined I am looking into a fix. FIX BELOW: (edit: please see the actual PR suggested, the below is a summary there are additional changes in PR)
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Theme/view/base/requirejs-config.js#L87
This also ensures the jquery mixin for security captcha is properly applied before jquery is called in context (before DOM requires call jquery and mixin is not applied). Do I get a coffee? :) lol |
@denis-g if you have time can you please apply my patch and run your tests to confirm all are resolved. |
@oaguilar5 please try my patch |
@AndresInSpace Here are the 2 file patches we have made for 2.4.7 Checkout-email-fix.patch And then we overwrote the lib files in: We're hoping that this resolves the issue where the email form isn't showing in the checkout. However, we are unable to replicate it reliably - even following peoples explanations using incog browser, new browser etc. It is very hard to replicate. I see you mention processing causing busy threads - is there a script we could put on to that would cause the issue to happen every time? |
It is from the thread being freed caused by the setTimeout in context.nextTick being wrapped inside the makeRequire that returns context.require which calls nextTick when require(['mixins'],...) is called to add magento mixins.js and overwrite require method. Your patch only addresses the mixin/config order and moves jquery call. Apply my patches fully and test. |
Maybe need additional fixes on #25587 request.
Preconditions (*)
Steps to reproduce (*)
requirejs-config.js
my-widget.js
my-widget-mixin.js
Expected result (*)
Mixin load and background is GREEN 🟢
Actual result (*)
Results depend on cache, opened devtools.
Background is RED 🔴 or GREEN 🟢
Background is RED 🔴 or GREEN 🟢
Background is GREEN 🟢 or RED 🔴
Background is GREEN 🟢 or RED 🔴
Background is RED 🔴, after event is GREEN 🟢
data-mage-init
– mixin load (works perfectly, without background flashing and mixin preloading)Background is GREEN 🟢
<div data-mage-init='{"myWidget": {}}'></div>
x-magento-init
– mixin load (works perfectly, without background flashing and mixin preloading)Background is GREEN 🟢
Background is GREEN 🟢
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
The text was updated successfully, but these errors were encountered: