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.56k stars 9.32k forks source link

Unable to save page and block changes using Page Builder with enabled js minification. #25620

Closed LordHansolo closed 11 months ago

LordHansolo commented 5 years ago

Preconditions (*)

  1. Magento 2.3.3 EE

Steps to reproduce (*)

  1. Stores->Settings->Configuration->Advanced->Developer->JavaScript Settings->Minify JavaScript Files = Yes
  2. Set production bin/magento deploy:mode:set production
  3. Go to Content->Elements->Blocks\Pages->Edit
  4. Make changes and Save

Expected result (*)

  1. Possibility to edit and save blocks and pages.

Actual result (*)

  1. Changes are not saved.

Additional Information

  1. I can see in browser console that Page Builder tries to load not minified resources. Since we have js minification enabled, in static content exists only minified js.
m2-assistant[bot] commented 5 years ago

Hi @LordHansolo. Thank you for your report. To help us process this issue please make sure that you provided the following information:

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:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@LordHansolo do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?


m2-assistant[bot] commented 4 years ago

Hi @engcom-Echo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

sdzhepa commented 4 years ago

Hello @LordHansolo

Thank you for contribution and collaboration!

This issue related to Page Builder functionality which is not part of Magento Open Source.

Current repository and issue tracker aimed at Magento Open Source version only and the main focus is community contribution/collaboration. It described in Issue reporting guidelines and it is a part of the issue report template:

Verify, that the issue you are about to report does not relate to the Magento Commerce. GitHub is intended for Magento Open Source users to report on issues related to Open Source only. There are no account management services associated with GitHub. You can report Commerce-related issues in one of two ways:

  • You can use the Support portal associated with your account
  • If you are a Partner reporting on behalf of a merchant, use the Partner portal.

But I have asked internal Magento team(who is working on Page Builder) about this issue and

mugua commented 4 years ago

Preconditions (*)

  1. Magento 2.3.3 EE

Steps to reproduce (*)

  1. Stores->Settings->Configuration->Advanced->Developer->JavaScript Settings->Minify JavaScript Files = Yes
  2. Set production bin/magento deploy:mode:set production
  3. Go to Content->Elements->Blocks\Pages->Edit
  4. Make changes and Save

Expected result (*)

  1. Possibility to edit and save blocks and pages.

Actual result (*)

  1. Changes are not saved.

Additional Information

  1. I can see in browser console that Page Builder tries to load not minified resources. Since we have js minification enabled in static content exists only minified js.

Hi Lordhansolo Have you fixed this issue now?

LordHansolo commented 4 years ago

Thank You @sdzhepa. Hello @mugua. Yes I fixed it. I will provide You part of code and places where they should appear.

In my module I created block that extends Magento\PageBuilder\Block\Adminhtml\Stage\Render and adds two additional methods isJsMinificationEnabled and getMinResolverAssetUrl.

<?php

namespace Fix\PageBuilder\Block\Adminhtml\Stage;

use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Asset\Minification;
use Magento\Framework\View\Element\Template\Context;
use Magento\PageBuilder\Block\Adminhtml\Stage\Render as ParentRender;
use Magento\PageBuilder\Model\Stage\Config;
use Magento\RequireJs\Model\FileManager;

/**
 * Class Render
 */
class Render extends ParentRender
{
    /**
     * @var FileManager
     */
    private $fileManager;

    /**
     * @var Minification
     */
    private $minification;

    /**
     * Class constructor
     *
     * @param Context $context
     * @param FileManager $fileManager
     * @param Config $config
     * @param Json $json
     * @param Minification $minification
     * @param array $data
     */
    public function __construct(
        Context $context,
        FileManager $fileManager,
        Config $config,
        Json $json,
        Minification $minification,
        array $data = []
    ) {
        parent::__construct($context, $fileManager, $config, $json, $data);

        $this->fileManager = $fileManager;
        $this->minification = $minification;
    }

    /**
     * Check that js minification is enabled
     *
     * @return boolean
     */
    public function isJsMinificationEnabled()
    {
        return $this->minification->isEnabled('js');
    }

    /**
     * Get min resolver asset url
     *
     * @return string
     */
    public function getMinResolverAssetUrl()
    {
        $minResolver = $this->fileManager->createMinResolverAsset();
        $url = $minResolver ? $minResolver->getUrl() : '';

        return $url;
    }
}

Next I created template in My module scope view/adminhtml/templates/stage/render.phtml with content from <magento_root>/vendor/magento/module-page-builder/view/adminhtml/templates/stage/render.phtml and add code below after <script src="<?= $block->escapeUrl($block->getRequireJsUrl()); ?>"></script>.

<?php if ($block->isJsMinificationEnabled()) : ?>
    <script src="<?= $block->escapeUrl($block->getMinResolverAssetUrl()); ?>"></script>
<?php endif ?>

Next I created Controller that extends Magento\PageBuilder\Controller\Adminhtml\Stage\Render. Copy entire execute method and override part below.

$renderBlock = $layout->createBlock(
    \Fix\PageBuilder\Block\Adminhtml\Stage\Render::class,
    'stage_render'
);
$renderBlock->setTemplate('Fix_PageBuilder::stage/render.phtml');

Next I created adminhtml/di.xml to set preference for Magento\PageBuilder\Controller\Adminhtml\Stage\Render.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\PageBuilder\Controller\Adminhtml\Stage\Render" type="Fix\PageBuilder\Controller\Adminhtml\Stage\Render" />
</config>

Next in module.xml I add Magento_PageBuilder to sequence.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Fix_PageBuilder" setup_version="1.0.0">
        <sequence>
            <module name="Magento_PageBuilder"/>
        </sequence>
    </module>
</config>

Thats all. Now Page Builder should work fine with enabled js minification.

mugua commented 4 years ago

@LordHansolo, Could you add my Skype: john.lou@msn.com or offer yours, Thanks. I have a little confuse about this, Thanks.

theCapypara commented 4 years ago

@mugua @LordHansolo If you have an active Magento Commerce subscription you can just ask the Commerce support and they'll send you a patch.

kushaljindal92 commented 4 years ago

I have made module based on @LordHansolo reply,, it is working perfectly. https://github.com/kushaljindal92/magentoee-pagebuilder-fix

dfelton commented 4 years ago

@Parakoopa Is this patch not listed in the Downloads section our accounts on Magento.com?

theCapypara commented 4 years ago

@dfelton As far as I know you have to open a support ticket and reference this GitHub issue. That's what we did and they sent us a patch.

vbuck commented 4 years ago

@sdzhepa I just want to thank you for carefully responding to the OP about this issue. There has been a habit of closing issues raised that mention Commerce Edition. Instead you chose to provide guidance anyway, and I think that's an example for Adobe to follow when dealing with the community, since Open-Source and Commerce are (for the time being) very closely related.

minhducnho commented 4 years ago

Does anyone have a patch to fix this, I have try to fix it but it still doesn't work? I have used @kushaljindal92's module but it only fix js errors, it still can't save

sdouma commented 4 years ago

Does Magento just not test? It seems pretty common for production instances to minify js files.

sunilit42 commented 2 years ago

@minhducnho any solution

aamoronatti commented 1 year ago

It's happening to me in Magento 2.4.6

rejith7 commented 1 year ago

Issue reported in 2.4.5 EE, especially while using google chrome with magento running on production mode and minified js enabled.

rejith7 commented 1 year ago

@anton-vidext did you use google chrome ? can you try using firefox? I'm beginning to think it's browser related issue

aamoronatti commented 1 year ago

@anton-vidext did you use google chrome ? can you try using firefox? I'm beginning to think it's browser related issue

I used google chrome, firefox and edge. It was happening in every browser.

Disabled minified JS and CSS and I can now save page builder content.

Hurrpadurr commented 1 year ago

Issue reported in 2.4.5 EE, especially while using google chrome with magento running on production mode and minified js enabled.

This is excatly what happens for me. Disabling minified doesn't help for me, but it only happens on Chrome.

VitaliyBoyko commented 1 year ago

Still reproducible in Magento 2.4.6

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

VitaliyBoyko commented 1 year ago

I made some investigation.

The CMS page form and the WYSIWYG editor are connected by the JQuery event which transfers the Page Builder instance from the editor to the form.

See: src/vendor/magento/module-page-builder/view/adminhtml/web/js/form/element/wysiwyg.js:91

src/vendor/magento/module-page-builder/view/adminhtml/web/js/form/form-mixin.js:27

events.on('pagebuilder:register', function (data) {
                if (data.ns === self.ns) {
                    self.pageBuilderInstances.push(data.instance);
                }
            });

If the form is initialized earlier than the editor (that often happens after the first/second save of the CMS page/block and page reload), the form is missing this event and doesn’t see the PB instance.

I've made a temporary hotfix for CMS Page in my project (maybe someone needs a quick solution):

diff --git a/vendor/magento/module-page-builder/view/adminhtml/web/js/form/form-mixin.js b/vendor/magento/module-page-builder/view/adminhtml/web/js/form/form-mixin.js
--- a/vendor/magento/module-page-builder/view/adminhtml/web/js/form/form-mixin.js   
+++ b/vendor/magento/module-page-builder/view/adminhtml/web/js/form/form-mixin.js   (date 1683647187438)
@@ -44,6 +44,16 @@
                 timeout,
                 locks;

+            let self = this;
+            if (_.isEmpty(this.pageBuilderInstances) & this.name === 'cms_page_form.cms_page_form') {
+                var registry = require('uiRegistry');
+                let contentComponent = registry.get(
+                    "cms_page_form.cms_page_form.content.content"
+                );
+
+                self.pageBuilderInstances.push(contentComponent.pageBuilder);
+            }
+
             if (_.isEmpty(this.pageBuilderInstances)) {
                 submit();
             } else {
m2-assistant[bot] commented 1 year ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 1 year ago

Verified the issue on Magento 2.4-develop instance with enterprise edition modules enabled and the issue is reproducible. Hence confirming the issue. image

github-jira-sync-bot commented 1 year ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-8773 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Bilalyounas1234 commented 1 year ago

Hi @LordHansolo Could you please explain about the

<?php if ($block->isJsMinificationEnabled()) : ?>

<?php endif ?>

Why did you add this in render.phtml because I have seen this template but I have not seen the script "" in this template maybe Magento remove this script from the latest version. if you can let me know the reason why you add this code then may I fix it in latest version thanks in advance

LordHansolo commented 1 year ago

Hello @Bilalyounas1234

In Magento 2.3.3 EE the render template probably looked like in the link below.

https://github.com/magento/magento2-page-builder/blob/v1.1.0/app/code/Magento/PageBuilder/view/adminhtml/templates/stage/render.phtml

Additionally You can see the Controller and the Block classes in version 1.6.0 looks different compared to version 1.1.0. Below I provide links to the render template, Render Block and Render Controller in version 1.1.0 and 1.6.0.

v.1.1.0

v.1.6.0

Looking at the solution I provided for Page Builder in Magento 2.3.3 EE, the code below was required to load min resolver in case js minification was enabled.

<?php if ($block->isJsMinificationEnabled()) : ?>
    <script src="<?= $block->escapeUrl($block->getMinResolverAssetUrl()); ?>"></script>
<?php endif ?>
engcom-Bravo commented 11 months ago

Hi @LordHansolo,

Tested on the latest 2.4-develop version. Enabled “Minify JavaScript Files” in the JavaScript Settings of Store Configuration. In production mode, attempted to edit a Block/Page and save it. Despite multiple edits, changes were successfully saved. After exhaustive attempts to reproduce this issue, it has been determined that the problem is no longer reproducible. Hence we are closing this issue.

https://github.com/magento/magento2/assets/51680745/127790b1-8e28-47cc-9ece-c42e1accce3b

Thanks.