Showing results for 
Search instead for 
Did you mean: 

Clarifying Unstated Assumptions for RequireJS Modules

Clarifying Unstated Assumptions for RequireJS Modules

In this GitHub issue:


A Magento employee made two curious statements. First

Sorry I didn't understand your proposal on utilizing x-magento-init.


General info: components in folders lib/web and app/code/Magento/Ui are global and may be utilized on any page. All other JS components are module specific and should be utilized when you develop extension to a specific module.

Regarding the x-magento-init statement -- I've been under the (incorrect?) assumption that creating a text/x-magento-init script tag that runs a Magento_Ui/js/core/app program is "the right" way to get server side rendered data into our javascript programs. Magento_Ui/js/core/app will load component JSON into the requirejs('uiRegistry') registry, which can then be used by other modules. Is Magento_Ui/js/core/app the right way to handle server side rendered data? Or is there another story here?


Regarding: "All other JS components are module specific". This seems -- wrong? A cursory search of Magento's core code shows places where this isn't true. For example, the Magento_Weee module uses modules from the Magento_Checkout module


#File: vendor/magento/module-weee/view/frontend/web/js/view/checkout/summary/weee.js
        /* ... */

Is it the intention of Magento's RequireJS implementation that modules can not use other module's source code unless those modules are in lib/web and app/code/Magento/Ui? If not, are there actual guidelines on what can and can't be used, or are things still a little loosey goosey here?


Re: Clarifying Unstated Assumptions for RequireJS Modules

  1. Your assumption about x-magento-init and Magento_Ui/js/core/app is correct. It should be used to configure Checkout UI components. Checkout JS app was built in parallel with Magento JS framework so some features are not fully used in it. As I stated in GitHub thread this, and some other Checkout refactorings are in backlog.
  2. There is no technical limitation of using other module's source code, but be aware that separation to public & private APIs for JS code is scheduled for 2.2. We plan to significantly increase @api coverage of PHP code and introduce @api coverage in JS code. Only code annotated with @api will be allowed to be used by third-party modules.