Javascript customer data, options is undefined in Firefox
-
15-03-2021 - |
Question
I have tis issue with the customer-data Javascript object. Her is (a par of my code)
define([
'jquery',
"Magento_Customer/js/customer-data"
], function ($, customerData) {
'use strict';
return function (config, element) {
customerData.reload(customerData.getExpiredSectionNames(), true).then(
function () {
let group = customerData.get('customer')();
//do stuff after getting customer data
}
);
}
});
I now the code can be approved by checking if the customer section needs a reload, but that is not the problem.
The code works fine in Chrome, but in Firefox I get the following error:
TypeError: options is undefined
The options get used in the getExpiredSectionNames() function on following line:
sectionLifetime = options.expirableSectionLifetime * 60
I guess this has to do with loading order of the javascript files.
So I tried moving the customer.customer.data
block in de default.xml but that didn't work either.
Is there a way I can insert the options in the customer-data object from my custom js script? Or do I need to add somthing in my requirjs-config.js file?
Solution 2
I finally found an answer. It was because I didn't add my dependencies in requirejs file.
requirejs-config.js
var config = {
paths: {
custom_js: 'js/custom',
},
shim: {
custom_js: ['jquery', 'Magento_Customer/js/customer-data']
},
}
I still find it strange that Chrome did load the dependencies correctly, but I'm happy I found a solution.
OTHER TIPS
Suppose you have an error in your customer/section/load
endpoint.
What does return http://your-localhost/customer/section/load ?