magento2
magento2 copied to clipboard
jquery.cookie dependency leads to JS issues with KO dependencies
Preconditions and environment
- 2.4.5
Steps to reproduce
From Twitter:
https://twitter.com/jissereitsma/status/1557372818257485834 I'm not getting this entirely yet, but a custom #magento 2.4.5 install had a theme with a global Require dep for "jquery/jquery.cookie": This suddenly caused all of the other JS (like KO) to fail silently.
https://twitter.com/jissereitsma/status/1557391198863638530 My theme had a requirejs-config.js with a global "dep" for "jquery/jquery.cookie". Simply because of that, an add-to-cart was not weird: The AJAX call towards the addtocart URL worked fine, with a valid reply. But then the customerData AJAX call was never made ... :o I'm baffled
https://twitter.com/vovayatsyuk/status/1557399058435686400 Looks like Magento can't load the same dependency using different names. You load 'js-cookie/cookie-wrapper' with 'jquery/jquery.cookie' alias, while magento load the same file using 'js-cookie/cookie-wrapper' string. Can be fixed at https://github.com/magento/magento2/blob/2.4-develop/lib/web/js-storage/js.storage.js#L17
@jissereitsma , @vovayatsyuk please, add additional information if I missed something
Expected result
It's possible to use aliases for jquery/jquery.cookie
Actual result
Issue caused all of the other JS (like KO) to fail silently.
Additional information
No response
Release note
No response
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [X] 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”.
Hi @sidolov. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
: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, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-6361
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-6361
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-6361
Hello @jissereitsma Could you please check if that patch resolve issue for you ?
---
lib/web/jquery/jquery.cookie.js | 11 +++++++++++
lib/web/js-storage/js.storage.js | 2 +-
.../module-theme/view/base/requirejs-config.js | 1 -
3 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 lib/web/jquery/jquery.cookie.js
diff --git a/lib/web/jquery/jquery.cookie.js b/lib/web/jquery/jquery.cookie.js
new file mode 100644
index 000000000..5268ae4ea
--- /dev/null
+++ b/lib/web/jquery/jquery.cookie.js
@@ -0,0 +1,11 @@
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+define([
+ 'jquery',
+ 'js-cookie/cookie-wrapper'
+], function () {
+
+});
diff --git a/lib/web/js-storage/js.storage.js b/lib/web/js-storage/js.storage.js
index b016fc0aa..0ac802854 100644
--- a/lib/web/js-storage/js.storage.js
+++ b/lib/web/js-storage/js.storage.js
@@ -14,7 +14,7 @@
(function (factory) {
var registeredInModuleLoader = false;
if (typeof define === 'function' && define.amd) {
- define(['jquery', 'js-cookie/cookie-wrapper'], factory);
+ define(['jquery', 'jquery/jquery.cookie'], factory);
registeredInModuleLoader = true;
}
if (typeof exports === 'object') {
diff --git a/vendor/magento/module-theme/view/base/requirejs-config.js b/vendor/magento/module-theme/view/base/requirejs-config.js
index 06e17f76d..911ff329d 100644
--- a/vendor/magento/module-theme/view/base/requirejs-config.js
+++ b/vendor/magento/module-theme/view/base/requirejs-config.js
@@ -68,7 +68,6 @@ var config = {
'jquery/validate': 'jquery/jquery.validate',
'jquery/file-uploader': 'jquery/fileUploader/jquery.fileuploader',
'prototype': 'legacy-build.min',
- 'jquery/jquery.cookie': 'js-cookie/cookie-wrapper',
'jquery/jquery-storageapi': 'js-storage/storage-wrapper',
'text': 'mage/requirejs/text',
'domReady': 'requirejs/domReady',
--
I am also experiencing this. For example, if call jquery.cookie
as dependency on the default.xml
layout
requirejs([
'jquery',
'jquery/jquery.cookie',
], function ($) {
});
Then:
- Header welcome message
- Minicart
- Checkout button ...
will not work.
Replace jquery/jquery.cookie
by js-cookie/cookie-wrapper
can make it work, but it needs to be compatible with Magento below 2.4.5
Hello @khoimm92 The provided fix resolves problem described by you. We checked it. Thank you for your collaboration
@xmav Sorry for the delay. As mentioned on twitter, I actually fixed the issue for myself earlier. But I tested out things out, and indeed the fix is good! Many thanks! Also thanks @sidolov @vovayatsyuk for helping along with this.
Hello @jissereitsma Could you please check if that patch resolve issue for you ?
--- lib/web/jquery/jquery.cookie.js | 11 +++++++++++ lib/web/js-storage/js.storage.js | 2 +- .../module-theme/view/base/requirejs-config.js | 1 - 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 lib/web/jquery/jquery.cookie.js diff --git a/lib/web/jquery/jquery.cookie.js b/lib/web/jquery/jquery.cookie.js new file mode 100644 index 000000000..5268ae4ea --- /dev/null +++ b/lib/web/jquery/jquery.cookie.js @@ -0,0 +1,11 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'js-cookie/cookie-wrapper' +], function () { + +}); diff --git a/lib/web/js-storage/js.storage.js b/lib/web/js-storage/js.storage.js index b016fc0aa..0ac802854 100644 --- a/lib/web/js-storage/js.storage.js +++ b/lib/web/js-storage/js.storage.js @@ -14,7 +14,7 @@ (function (factory) { var registeredInModuleLoader = false; if (typeof define === 'function' && define.amd) { - define(['jquery', 'js-cookie/cookie-wrapper'], factory); + define(['jquery', 'jquery/jquery.cookie'], factory); registeredInModuleLoader = true; } if (typeof exports === 'object') { diff --git a/vendor/magento/module-theme/view/base/requirejs-config.js b/vendor/magento/module-theme/view/base/requirejs-config.js index 06e17f76d..911ff329d 100644 --- a/vendor/magento/module-theme/view/base/requirejs-config.js +++ b/vendor/magento/module-theme/view/base/requirejs-config.js @@ -68,7 +68,6 @@ var config = { 'jquery/validate': 'jquery/jquery.validate', 'jquery/file-uploader': 'jquery/fileUploader/jquery.fileuploader', 'prototype': 'legacy-build.min', - 'jquery/jquery.cookie': 'js-cookie/cookie-wrapper', 'jquery/jquery-storageapi': 'js-storage/storage-wrapper', 'text': 'mage/requirejs/text', 'domReady': 'requirejs/domReady', --
Working fine for me!
https://github.com/magento/magento2/commit/bc2b48a284888d33e5300df29f6c81a354822d64
Is this patch released? I am facing this issue on ver. 2.4.5-p1 also.
That patch fixed my issue on M2.4.5-p2 tnx. I had similar issue, the proceed to checkout button was not working. Add to cart was not showing any notifications that a product is added to a cart.