magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

[Issue] Load color picker dependencies only when it is actually used #28477

Open ghost opened 4 years ago

ghost commented 4 years ago

This issue is automatically created based on existing pull request: magento/magento2#28400: Load color picker dependencies only when it is actually used


Preconditions (*)

This is just another performance PR, which focuses on loading only the needed dependencies. This time I am optimizing color picker component and its spectrum and tinycolor dependencies.

Loading mentioned modules dynamically saves us 2 JavaScript requests and 123,6kB (28,3kB gzipped) from downloading and parsing.

This change is covered by unit tests that had to be adjusted to take asynchronous dependencies loading into account.

Steps to reproduce (*)

  1. Verify that spectrum.js and tinycolor.js are no longer loaded by default.
  2. Verify that above modules are loaded and color picker works as expected when used (see comment above to find out how to add it).

Actual Result: :heavy_multiplication_x: spectrum.jsand tinycolor.js are loaded by default

2020-09-02_12-33

Expected Result: :heavy_check_mark: spectrum.js and tinycolor.js should no loaded by default.

Questions or comments

While making sure this change doesn't break anything I found out that colorPicker binding is not used anywhere in Magento. The easiest way to get it is to for example add it to app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml:

<field name="color_picker_test">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/form/element/color-picker</item>
            <item name="template" xsi:type="string">ui/form/field</item>
            <item name="elementTmpl" xsi:type="string">ui/form/element/color-picker</item>
            <item name="label" xsi:type="string">Background Color (hex)</item>
            <item name="labelVisible" xsi:type="boolean">true</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">text</item>
            <item name="formElement" xsi:type="string">input</item>
            <item name="source" xsi:type="string">category_form</item>
        </item>
    </argument>
</field>

and test it in category edit form.

Contribution checklist (*)

magento-engcom-team commented 4 years ago

:white_check_mark: Confirmed by @engcom-Alfa Thank you for verifying the issue. Based on the provided information internal tickets MC-37314 were created

Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.