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

Can't compile style for custom theme which inherits from another custom theme #35684

Open Eddcapone opened 2 years ago

Eddcapone commented 2 years ago

Preconditions and environment

Code:

issue_35684.zip (extract to root dir of the magento project)

Steps to reproduce

Overview

  1. Create Theme Foo (inheriting from Magento/luma)
  2. Create Theme Bar (inheriting from Foo)
  3. Create Module Company_Test
  4. Setup Upgrade
  5. Grunt configuration
  6. Grunt Refresh

1. Create Theme Foo (inheriting from Magento/luma)

1.1 app/design/frontend/company/foo/registration.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/company/foo', __DIR__);

1.2 app/design/frontend/company/foo/theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Foo</title>
    <parent>Magento/luma</parent>
</theme>

1.3 app/design/frontend/company/foo/web/css/source/_extend.less

@import '_mixin.less';

1.4 app/design/frontend/company/foo/web/css/source/_mixin.less

.h1 {
    color: red;
    font-size: 24px;
}

2. Create Theme Bar (inheriting from Foo)

2.1 app/design/frontend/company/bar/registration.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/company/bar', __DIR__);

2.2 app/design/frontend/company/bar/theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Bar</title>
    <parent>company/foo</parent>
</theme>

2.3 app/design/frontend/company/bar/web/css/source/_extend.less

@import '_text.less';

2.4 app/design/frontend/company/bar/web/css/source/_text.less

.black { color: black; }

3. Create Module Company_Test

3.1 app/code/Company/Test/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Company_Test',
    __DIR__
);

3.2 app/code/Company/Test/etc/module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Company_Test" setup_version="1.0.0"/>
</config>

3.3 app/code/Company/Test/view/frontend/web/css/source/_module.less

body.contact-index-index {
    .page-title { .h1(); }
}

3.4 Enable Module "Company_Test"

php bin/magento module:enable Company_Test

4. Setup Upgrade

php bin/magento setup:upgrade

5. Grunt Configuration

dev/tools/grunt/configs/local-themes.js

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

 'use strict';

 /**
  * Define Themes
  *
  * area: area, one of (frontend|adminhtml|doc),
  * name: theme name in format Vendor/theme-name,
  * locale: locale,
  * files: [
  * 'css/styles-m',
  * 'css/styles-l'
  * ],
  * dsl: dynamic stylesheet language (less|sass)
  *
  */
 module.exports = {
     company_foo: {
         area: 'frontend',
         name: 'company/foo',
         locale: 'de_DE',
         files: [
             'css/styles-m',
             'css/styles-l'
         ],
         dsl: 'less'
     },
     company_bar: {
         area: 'frontend',
         name: 'company/bar',
         locale: 'de_DE',
         files: [
             'css/styles-m',
             'css/styles-l'
         ],
         dsl: 'less'
     },
 };

6. Grunt Refresh

Run grunt refresh

Expected result

It should compile without an error.

Actual result

-> .h1 is undefined

user@xx-VirtualBox:/var/www/company/fresh_m244$ grunt refresh
Running "refresh" task

Running "clean:var" (clean) task
>> 1433 paths cleaned.

Running "clean:pub" (clean) task
>> 1194 paths cleaned.

Running "clean:styles" (clean) task
>> 0 paths cleaned.

Running "clean:markup" (clean) task
>> 0 paths cleaned.

Running "clean:js" (clean) task
>> 0 paths cleaned.

Running "clean:generation" (clean) task
>> 1732 paths cleaned.

Running "clean:company_foo" (clean) task
>> 0 paths cleaned.

Running "clean:company_bar" (clean) task
>> 0 paths cleaned.

Running "exec:all" (exec) task
grunt --force clean:company_foo
Processed Area: frontend, Locale: de_DE, Theme: company/foo, File type: less.
-> css/styles-m.less
-> css/styles-l.less
Successfully processed.
Running "clean:company_bar" (clean) task
>> 49 paths cleaned.

Done.

Execution Time (2022-07-22 11:58:46 UTC+2)
loading tasks      92ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 68%
clean:company_bar  42ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 31%
Total 135ms

Processed Area: frontend, Locale: de_DE, Theme: company/bar, File type: less.
-> css/styles-m.less
-> css/styles-l.less
Successfully processed.

Running "less:company_foo" (less) task
>> 2 stylesheets created.
>> 2 sourcemaps created.

Running "less:company_bar" (less) task
>> pub/static/frontend/company/bar/de_DE/Company_Test/css/source/_module.less: [L2:C18] .h1 is undefined
Warning: Error compiling pub/static/frontend/company/bar/de_DE/css/styles-m.less Use --force to continue.

Aborted due to warnings.

Execution Time (2022-07-22 11:58:33 UTC+2)
clean:var         305ms  ▇▇ 1%
clean:pub         382ms  ▇▇ 1%
clean:generation  324ms  ▇▇ 1%
exec:all          21.8s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 80%
less:company_foo   3.8s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 14%
less:company_bar  478ms  ▇▇▇ 2%
Total 27.4s

Additional information

If I skip 2.3 and 2.4 then compilation works.

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @Eddcapone. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

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:

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

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

mrtuvn commented 2 years ago

styles in module you will not get ability to use some default value than theme. From my experiences, current some value/variables can't call from module scope less. Write styles from module or theme not have much differences. Magento wrap all styles into final css output

Eddcapone commented 2 years ago

@mrtuvn Then how can I solve it? It looks like a magento bug to me.

mrtuvn commented 2 years ago

Just curious why not to use in theme scope/area in app/design

mrtuvn commented 2 years ago

You can try this approach (but this is custom module) not default function of magento https://github.com/swissup/module-rtl#less-mixins

Eddcapone commented 2 years ago

Just curious why not to use in theme scope/area in app/design

Because it is only needed for the extension. If the extension is not active e.g. because it is only enabled for a certain store view, then the style is not needed. If I would put it in the theme, then it would load all the time.

mrtuvn commented 2 years ago

Oke make more senses to me!

mrtuvn commented 2 years ago

In your specific case you can import mixins in your module like this

_module.less

@import (reference) '_mixins';
// Other styles

_mixins you can use syntax like https://github.com/magento/magento2/blob/2.4-develop/app/design/frontend/Magento/blank/web/css/source/_extends.less

@abs-yourmixins-name: {
    //Any code less/css here
};

.h1() {
 // Any code less/css here
}
mrtuvn commented 2 years ago

From my experiences from module scope (app/code/ or vendor/magento/ v.v) you only use variables from magento lib/web/css You can't get variables/mixins define in app/design

Eddcapone commented 2 years ago

From my experiences from module scope (app/code/ or vendor/magento/ v.v) you only use variables from magento lib/web/css You can't get variables/mixins define in app/design

Thats not true. I just tested it and it works. I defined a mixin in my theme and used it in the module successfully.

It just does not work if you create another theme which is a child theme of your first theme like described in my bug report.

mrtuvn commented 2 years ago

current my client used v2.3.3. I can't call mixins defined in child theme from module app/code. Got issue mixin undefined I don't have instance test in higher version for re-test this case

engcom-Echo commented 2 years ago

Hello @Eddcapone,

We have tried to reproduce this issue on latest 2.4-develop branch but unable to reproduce and below are the steps which i have https://github.com/magento/magento2/issues/35684.

  1. Create Theme Foo (inheriting from Magento/luma)
  2. Create Theme Bar (inheriting from Foo)
  3. Create Module Company_Test
  4. Setup Upgrade
  5. Grunt configuration
  6. Grunt Refresh

Please find the attached screen for your reference.

image

Please provide more information for this issue so that we can reproduce.

Thanks

m2-assistant[bot] commented 2 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:


Eddcapone commented 2 years ago

Hello @engcom-Echo, please upload the code you were using for your test as a .zip so I can have a look and compare with mine.

mrtuvn commented 2 years ago

Can you share sample of your ? @Eddcapone

Eddcapone commented 2 years ago

@mrtuvn Yes, here is my code:

issue_35684.zip (extract to root dir of the magento project)

@engcom-Echo , I forgot to add this step to the description, can you please check if the module is enabled?

3.4 Enable Module "Company_Test" php bin/magento module:enable Company_Test

I also added my compilation output.

engcom-Echo commented 2 years ago

@Eddcapone,

Thanks for sharing more information. we have tried to reproduce this issue on 2.4-develop branch and now it is reproducible and below are the steps which i have follow #35684

my code zip file. Issue35684.zip(extract to root dir of the magento project)

  1. Create Theme Foo (inheriting from Magento/luma)
  2. Create Theme Bar (inheriting from Foo)
  3. Create Module Company_Test
  4. Enable Module
  5. Setup Upgrade
  6. Grunt configuration
  7. Grunt Refresh

Please find the attached screen for your reference.

image

Hence, the issue reported is reproducible and confirmed.

Thanks

github-jira-sync-bot commented 2 years ago

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

m2-assistant[bot] commented 2 years ago

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

leonhelmus commented 2 years ago

For me i also have an error that less files are not showing anymore in browser after the compile is done with: grunt clean && grunt exec && grunt less After i upgraded to 2.4.4 and used the sample Gruntfile & package.json, but then i followed this post: https://stackoverflow.com/questions/73234428/why-not-showing-less-file-path-in-browser-after-running-grunt-in-magento2 And added: "grunt-contrib-less": "~1.4.1" to my Gruntfile and it started working again and i saw less references in browser.