Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@import (once) breaks with indirection #2444

Closed
seriema opened this issue Feb 11, 2015 · 7 comments
Closed

@import (once) breaks with indirection #2444

seriema opened this issue Feb 11, 2015 · 7 comments

Comments

@seriema
Copy link

seriema commented Feb 11, 2015

Frankly I'm not sure if this is a bug or a feature, but it's not behaving as I'd expect from reading the docs.

Doc's on import-once:

The default behavior of @import statements. It means the file is imported only once and subsequent import statements for that file will be ignored.

So if I include a file twice, it's included the first time and ignored subsequent times. Ok. But if I include that file indirectly and then directly then it's using the last import and not the first that's used.

I have lessc 2.3.1 (Less Compiler) [JavaScript].

The files

style.less

span:before {
  content: 'stylefile';
}

wrapper.less

@import "style";

Use case 1, where it works

main1.less

@import "style"; // Including the file directly.

span:before {
  content: 'mainfile';
}

@import "style";

main1.css

span:before {
  content: 'stylefile';
}
span:before {
  content: 'mainfile';
}

Use case 2, where it's wrong

main2.less

@import "wrapper";  // Including style.less indirectly.

span:before {
  content: 'mainfile';
}

@import "style";

main2.css

span:before {
  content: 'mainfile';
}
span:before {
  content: 'stylefile';
}

Is this a bug or is there something I've missed? Because now my stuff gets overwritten.

@seven-phases-max
Copy link
Member

I suppose this is because of #1617 (comment).

@lukeapage
Copy link
Member

as I said there

because imports work as a breadth first tree search, not a depth first tree search.. It doesn't execute them asyncronously, it puts them in the order it finds them (but searching and honouring imports at a lower level, not a deeper level). its always been that way and changing it now would fix this example and break another.

If someone has put the 2nd import in the top level file because the specificity demands it go later then fixing this would mean it is put earlier, not later. So my thoughts are that its less likely to cause a problem with the current technique.

Also IMO if you are importing files multiple times and relying on ordering, you are doing something wrong!

@seriema
Copy link
Author

seriema commented Feb 12, 2015

I deleted my previous comment =)

I agree that our LESS is pretty crazy, but I'd expect it to generate unnecessarily large CSS with duplicate selectors and that's completely our own fault. I'm hoping that reference might be a better option for us. Still though, based on the documentation and any use case I can think of I don't see how the current behavior would be expected by anyone.

@patricklx
Copy link

also, multiple namespace import wont work anymore. e.g.:
.foo {@import 'special'}
.bar {@import 'special'} <-- not done

@seven-phases-max
Copy link
Member

@patricklx

For your example you need to use multiple option and it's been this way since version 1.4.0.

@syuilo
Copy link

syuilo commented Dec 11, 2015

For your example you need to use multiple option and it's been this way since version 1.4.0.

Great! I solved similar problem. thanks.

@stale
Copy link

stale bot commented Nov 14, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 14, 2017
@stale stale bot closed this as completed Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@lukeapage @seriema @patricklx @syuilo @seven-phases-max and others