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

"Area code not set" after update to 2.4.5-p8 #38845

Closed dmitryp1993 closed 3 months ago

dmitryp1993 commented 5 months ago

Preconditions and environment

Steps to reproduce

Enable Magento_CSP, and set "dev/js/translate_strategy" to "embedded". Than run bin/magento setup:static-content:deploy

Expected result

Successful finish

Actual result

Error: Area code not set

image (12)

Additional information

Exception is triggered in class vendor/magento/framework/Translate.php

 /**
     * Initialize translation data
     *
     * @param string|null $area
     * @param bool $forceReload
     * @return $this
     */
    public function loadData($area = null, $forceReload = false)
    {
        $this->_data = [];
        if ($area === null) {
            $area = $this->_appState->getAreaCode();
        }

Stack trace image (11)

Possible solution - emulate area code in vendor/magento/module-deploy/Service/DeployRequireJsConfig.php

/**
     * @param string $areaCode
     * @param string $themePath
     * @param string $localeCode
     * @return bool true on success
     */
    public function deploy($areaCode, $themePath, $localeCode)
    {
        /** @var \Magento\Framework\View\Design\ThemeInterface $theme */
        $theme = $this->themeList->getThemeByFullPath($areaCode . '/' . $themePath);
        /** @var \Magento\Theme\Model\View\Design $design */
        $design = $this->designFactory->create()->setDesignTheme($theme, $areaCode);
        /** @var ResolverInterface $locale */
        $locale = $this->localeFactory->create();
        $locale->setLocale($localeCode);
        $design->setLocale($locale);

        $assetRepo = $this->assetRepoFactory->create(['design' => $design]);
        /** @var \Magento\RequireJs\Model\FileManager $fileManager */
        $fileManager = $this->fileManagerFactory->create(
            [
                'config' => $this->requireJsConfigFactory->create(
                    [
                        'assetRepo' => $assetRepo,
                        'design' => $design,
                    ]
                ),
                'assetRepo' => $assetRepo,
            ]
        );

        \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\App\State::class)->emulateAreaCode(
            $areaCode,
            [$fileManager, 'createRequireJsConfigAsset']
        );

        //$fileManager->createRequireJsConfigAsset();

        $fileManager->createMinResolverAsset();

        return true;
    }

Release note

No response

Triage and priority

m2-assistant[bot] commented 5 months ago

Hi @dmitryp1993. Thank you for your report. To speed up processing of this issue, 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:

dmitryp1993 commented 5 months ago

@magento give me 2.4.5-p8 instance

magento-deployment-service[bot] commented 5 months ago

Hi @dmitryp1993. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 5 months ago

Hi @dmitryp1993, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

dmitryp1993 commented 5 months ago

@magento give me 2.4.5-p8 instance

magento-deployment-service[bot] commented 5 months ago

Hi @dmitryp1993. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 5 months ago

Hi @dmitryp1993, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

m2-assistant[bot] commented 5 months ago

Hi @engcom-Delta. 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:

dmitryp1993 commented 5 months ago

@magento give me 2.4.5-p8 instance

magento-deployment-service[bot] commented 5 months ago

Hi @dmitryp1993. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 5 months ago

Hi @dmitryp1993, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

engcom-Delta commented 5 months ago

Hi @dmitryp1993 ,

Verified the issue on 2.4-develop and it is reproducible.

Hence, Confirming the issue.

Steps to reproduce:-

  1. Enable Magento_CSP module
  2. Set"dev/js/translate_strategy" is to embedded
  3. Set deployment mode to production
  4. Run bin/magento setup:static-content:deploy

Magento_CSP module is enabled

Screenshot 2024-06-21 at 6 35 16 PM

"dev/js/translate_strategy" is set to "embedded"

Screenshot 2024-06-21 at 6 24 05 PM

Deployment mode - production

Screenshot 2024-06-21 at 6 35 58 PM

bin/magento setup:static-content:deploy

Screenshot 2024-06-21 at 6 36 11 PM
github-jira-sync-bot commented 5 months ago

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

m2-assistant[bot] commented 5 months ago

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

quterorta commented 4 months ago

@magento I am working on this