You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly #1968
changed the title [-]When importing using reference, mixins that container an & selector get added to the compiled output[/-][+]When @importing using (reference), mixins that contain a & selector get added to the compiled output[/+]on Apr 12, 2014
changed the title [-]When @importing using (reference), mixins that contain a & selector get added to the compiled output[/-][+]When using @import (reference), mixins that contain an & selector get added to the compiled output[/+]on Apr 12, 2014
changed the title [-]When using @import (reference), mixins that contain an & selector get added to the compiled output[/-][+]When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly[/+]on Apr 12, 2014
I can't reproduce the CSS output of your example with Less 1.7.0.
As for Bootstrap, the non empty reference output is the result of extend directives (&:extend(.clearfix all);, &:extend(.btn-*); etc.) which is a different issue (see #1851, #1878).
Here is the same issue using bootstrap files, with one tweak to remove the 2 extend statements you mention are problematic.
style.less
@import"bootstrap-3.1/less/variables.less";
@import"bootstrap-3.1/less/mixins.less"; //modified to comment out &:exend() statements@import (reference) "bootstrap-3.1/less/buttons.less";
OK, I see now. The problem there is that (reference) is not inheritable across multiple files. If mixins.less is imported from buttons.less it inherits the reference modifier so the output is empty. But when mixins.less is included directly in the master file with no sign of reference, all classes generated there get into the output. (Workaround is obvious: put (reference) on mixins.less too).
Suggestion: add @import "mixin.less"; to the style.less in your original example. (Otherwise it's not that evident how to reproduce your results. Many developers follow the "import things where they are used" guidelines and that way (i.e. mixin.less imported within less-for-reference.less) it works as expected).
It's important to realize that even if this (and similar) bug is fixed once it will be no guarantee it's not broken with further Bootstrap releases - simply because "bootstrap.less" is meant to generate CSS - so they never will bother if or if not it's compatible with whatever sort-of-kludge features that may try to hack it externally.
I think the issue is that you should avoid mixing-in against compiled CSS (or, in your case what is the equivalent of compiled CSS as you are importing essentially a manifest-like LESS file).
This is how I layout my Less files - it might prove helpful to others. Because I segregate the base less files from bootstrap (into /third-party), and further differentiate between custom and override styles, I have been able to keep pace with bootstrap version updates with minimal disruption.
Directory Structure
/static
/third-party
/bootstrap-3.3.1 (unmodified content from bootstrap 3.3.1)
/less
variables.less (I do not use this file)
mixins.less
...(all other bootstrap .less files)
/js (this is where all unedited js files from bootstrap reside)
/less
/corp
/global
styles.less (site style used throughout corp site)
/views
page1.less (site style for just page 1)
page2.less (site style for just page 2)
... (all other per page .less files)
/shared
prerequisites.less (contains references to variables and mix-ins from all sources)
postrequisites.less (contains references to utils and responsive utils from all sources)
/corp-boostrap-3.3.1
/custom (contains customizations not found in bootstrap)
variables.less (custom variables.less not defined by bootstrap)
mixins.less (custom mixins not defined by bootstrap)
/override (contains overrides of bootstrap styles)
variables.less (same as variables.less from bootstrap, but with values for my corp)
mixins.less (overrides from bootstrap)
Files
Pre- and post- requisites.less
prerequisites.less
This is the file that facilitates sharing of variables and mixins with site styles and page styles.
//
// similar to bootstrap.less, but contains overrides and customizations.
//
@import"../shared/prerequisites.less"// Reset and dependencies
@import"../../../_third-party/bootstrap-3.3.1/less/normalize.less";@import"../../../_third-party/bootstrap-3.3.1/less/print.less";
// Core CSS
@import"../../../_third-party/bootstrap-3.3.1/less/scaffolding.less";@import"../../../_third-party/bootstrap-3.3.1/less/type.less";...(other core CSS @imports from _third-party/)// Components (only@import what is used by corp site)@import"../../../_third-party/bootstrap-3.3.1/less/dropdowns.less";...(other components @imports from _third-party/)// Components w/ JavaScript (only@import what is used by corp site)@import"../../../_third-party/bootstrap-3.3.1/less/modals.less";@import"../../../_third-party/bootstrap-3.3.1/less/carousel.less";
// Components: Corp Customizations
@import"../../corp-bootstrap-3.3.1/custom/global.less";@import"../../corp-bootstrap-3.3.1/custom/chrome.less";
// Components: Corp Override
@import"../../corp-bootstrap-3.3.1/override/grid.less";@import"../../corp-bootstrap-3.3.1/override/type.less";...(other @imports overrides)@import"../shared/postrequisites.less"
page1.less (example of page-specific style)
@import"../shared/prerequisites.less"... page css here
@import"../shared/postrequisites.less"
@bcullman I suppose that any frontend developer that extends a CSS framework will end up with the same kind of structure and import ordering (even if yours sounds, imho, over-complicated and probably misses the point with one dedicated stylesheet per page).
Use @import (reference) to import external files, but without adding the imported styles to the compiled output unless referenced.
Therefore, whatever messy imports I may be using, the @import (reference) statement line should output exactly zero characters. Otherwise, please, update the docs explaining why it's not the case if this issue does not deserve to be fixed.
@almeidap for the record, I don't have anywhere near one dedicated stylesheet per page. But when they are needed, I have a place to put them.
As for the issue at hand, I think that @seven-phases-max noted in an earlier answer to this that (reference) is not inheritable across multiple files.
This is why I posted how my files are structured. I never double (reference) because all my necessary references are in my prerequisites.less file, which is shared by my overall corp style as well as any individual page styles I need.
You forgot the project is a volunteer-based open source one, did you? The docs are open source as well. So please, let's take it a bit more easy (the issue is marked as bug and my comments are mostly intended to help to avoid stepping into this bug with a bit more structured project files organization, that's it).
@seven-phases-max For sure, I did not forget that less.js is a volunteer-based project and I am very grateful to the contributors. I just wanted to bring the focus back to the issue itself instead of not-so-useful (imo) discussions about the usage of imports.
I recently started refactoring our LESS resources as our framework hit the IE stylesheets limit when concatenated with other CSS project files. Fixing the (reference) import issue will help me to avoid duplicate selectors and better control outputted resources.
Activity
[-]When importing using reference, mixins that container an & selector get added to the compiled output[/-][+]When @importing using (reference), mixins that contain a & selector get added to the compiled output[/+][-]When @importing using (reference), mixins that contain a & selector get added to the compiled output[/-][+]When using @import (reference), mixins that contain an & selector get added to the compiled output[/+][-]When using @import (reference), mixins that contain an & selector get added to the compiled output[/-][+]When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly[/+]thomaswelton commentedon Apr 22, 2014
I can replicate this error. Using twitter bootstrap and importing it as a reference generates a lot of output I did not expect to see
bcullman commentedon Apr 22, 2014
Yes, I discovered this when working with bootstrap too. I built this example to simplify the issue down a bit.
seven-phases-max commentedon Apr 23, 2014
I can't reproduce the CSS output of your example with Less 1.7.0.
As for Bootstrap, the non empty
referenceoutput is the result ofextenddirectives (&:extend(.clearfix all);,&:extend(.btn-*);etc.) which is a different issue (see #1851, #1878).bcullman commentedon Apr 25, 2014
Here is the same issue using bootstrap files, with one tweak to remove the 2 extend statements you mention are problematic.
style.less
Output should be nothing. However, I get
seven-phases-max commentedon Apr 26, 2014
@bcullman
OK, I see now. The problem there is that
(reference)is not inheritable across multiple files. Ifmixins.lessis imported frombuttons.lessit inherits thereferencemodifier so the output is empty. But whenmixins.lessis included directly in the master file with no sign ofreference, all classes generated there get into the output. (Workaround is obvious: put(reference)onmixins.lesstoo).Suggestion: add
@import "mixin.less";to thestyle.lessin your original example. (Otherwise it's not that evident how to reproduce your results. Many developers follow the "import things where they are used" guidelines and that way (i.e.mixin.lessimported withinless-for-reference.less) it works as expected).bcullman commentedon Apr 28, 2014
@seven-phases-max
That does work. I am willing to consider this matter closed.
16 remaining items
seven-phases-max commentedon Dec 16, 2014
What you need is to split the front-end (e.g. the CSS) part of
file1.lessfrom the shared "config" part (i.e. Bootstrap overrides), e.g.:It's important to realize that even if this (and similar) bug is fixed once it will be no guarantee it's not broken with further Bootstrap releases - simply because "bootstrap.less" is meant to generate CSS - so they never will bother if or if not it's compatible with whatever sort-of-kludge features that may try to hack it externally.
gdelhumeau commentedon Dec 16, 2014
Then I don't see what is the goal of the reference option.
bcullman commentedon Dec 16, 2014
I think the issue is that you should avoid mixing-in against compiled CSS (or, in your case what is the equivalent of compiled CSS as you are importing essentially a manifest-like LESS file).
This is how I layout my Less files - it might prove helpful to others. Because I segregate the base less files from bootstrap (into /third-party), and further differentiate between custom and override styles, I have been able to keep pace with bootstrap version updates with minimal disruption.
Directory Structure
Files
Pre- and post- requisites.less
prerequisites.less
This is the file that facilitates sharing of variables and mixins with site styles and page styles.
postrequisites.less
html page referenced .less files
styles.less (used on all pages)
page1.less (example of page-specific style)
almeidap commentedon Dec 16, 2014
@bcullman I suppose that any frontend developer that extends a CSS framework will end up with the same kind of structure and import ordering (even if yours sounds, imho, over-complicated and probably misses the point with one dedicated stylesheet per page).
The problem here, as @gdelhumeau spots it, is that the
referencefeature does not respect its contract as stated in the docs (http://lesscss.org/features/):Therefore, whatever messy imports I may be using, the
@import (reference)statement line should output exactly zero characters. Otherwise, please, update the docs explaining why it's not the case if this issue does not deserve to be fixed.bcullman commentedon Dec 16, 2014
@almeidap for the record, I don't have anywhere near one dedicated stylesheet per page. But when they are needed, I have a place to put them.
As for the issue at hand, I think that @seven-phases-max noted in an earlier answer to this that (reference) is not inheritable across multiple files.
This is why I posted how my files are structured. I never double (reference) because all my necessary references are in my prerequisites.less file, which is shared by my overall corp style as well as any individual page styles I need.
seven-phases-max commentedon Dec 17, 2014
@almeidap
You forgot the project is a volunteer-based open source one, did you? The docs are open source as well. So please, let's take it a bit more easy (the issue is marked as bug and my comments are mostly intended to help to avoid stepping into this bug with a bit more structured project files organization, that's it).
almeidap commentedon Dec 17, 2014
@seven-phases-max For sure, I did not forget that less.js is a volunteer-based project and I am very grateful to the contributors. I just wanted to bring the focus back to the issue itself instead of not-so-useful (imo) discussions about the usage of imports.
I recently started refactoring our LESS resources as our framework hit the IE stylesheets limit when concatenated with other CSS project files. Fixing the
(reference)import issue will help me to avoid duplicate selectors and better control outputted resources.XWIKI-11408: Menu Application: Improve default look to make it better…
assadtony commentedon Apr 28, 2015
Any updates on this issue? :)
thybzi commentedon Oct 25, 2015
Wish that to be fixed. My
.clearfixmixin runs many-many times on the same selector, because it contains&:afterSomMeri commentedon Oct 26, 2015
I am working on import reference now, but I am not able to give out estimate.
Fixing import by reference
SomMeri commentedon Dec 7, 2015
This should be fixed by #2729 .