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

Imports are not updated when recompiling via the same (?) less object #3185

Closed
xinglie opened this issue Mar 7, 2018 · 19 comments
Closed

Imports are not updated when recompiling via the same (?) less object #3185

xinglie opened this issue Mar 7, 2018 · 19 comments

Comments

@xinglie
Copy link

xinglie commented Mar 7, 2018

bug report
I write a compile tool for my project, it depend less.

my project style folder and files likes

- styles
   _utils.less
   index.less

and index.less content is

@import "./utils"

I use less api to compile the less files like

let less=require('less');
//....
less.render(indexContent,options,(err,result)=>{
       console.log(result.css)
});

when i change _utils.less content , the above code will automatically execute

but since 3.0.x , when i change _utils.less content ,the result.css is the first time result, whatever change how many times.

but 2.7.x is ok, when i change _utils.less content ,the result.css also changed.

@seven-phases-max seven-phases-max changed the title 3.0.x bug and 2.7.x is ok Imports are not updated when recompiling via the same (?) less object Mar 7, 2018
@seven-phases-max
Copy link
Member

seven-phases-max commented Mar 7, 2018

Sounds similar to gulp-community/gulp-less#283.
I guess in a these "auto-watch" cases it's the same Less object used to compile each update, right? Then I guess it's something with not reseting some imports cache between different render calls or somewhat like that.

@xinglie
Copy link
Author

xinglie commented Mar 7, 2018

@seven-phases-max yes,use the same Less object to compile each update.
i am not use gulp-less tool, i use less api directly .
it seems less cache the result and not update correctly

@seven-phases-max
Copy link
Member

So the quick workaround (until the bug is fied) in your case wil be in:

require('less').render(indexContent,options,(err,result)=>{
       console.log(result.css)
});

@shobhitsharma
Copy link

Yes, it seems the issue lies in this commit where the calltree is manipulated based on arguments a48c24c#diff-a6b31db4e862654ae597161e441689bb

@seven-phases-max
Copy link
Member

seven-phases-max commented Mar 9, 2018

it seems the issue lies in this commit ...

Hmm, honestly there I can't see anything that could affect imports...

@tiodot
Copy link

tiodot commented Mar 14, 2018

In Node environment, manual clear less compile cached file:

const less = require('less');
const fileManagers = less.environment && less.environment.fileManagers || [];
fileManagers.forEach(fileManager => {
     if (fileManager.contents) {
               fileManager.contents = {};
     }
});

@TigersWay
Copy link

Thanks @tiodot it seems to be working so far... But hope we'll get a "cleaner" way soon!

@matthew-dean
Copy link
Member

It might have something to do with these lines added for 3.0. https://github.com/less/less.js/blob/master/lib/less/tree/mixin-definition.js#L9

Try removing the specific if/else to just the else statement and see if the problem still happens. If it doesn't, this optimization may need to be removed. However, what would be more ideal is clearing the file manager or any internal cache per new parse/render call.

@stephenlacy
Copy link

Just checking if there are any updates for this issue?
gulp-less is getting quite a few developers hitting this.

@TigersWay
Copy link

Just gave another try a few hours ago and it seemed to be working fine (without patch). Anyone else?

  "dependencies": {
    "browser-sync": "^2.24.4",
    "gulp": "^4.0.0",
    "gulp-autoprefixer": "^5.0.0",
    "gulp-clean-css": "^3.9.4",
    "gulp-hb": "^7.0.1",
    "gulp-less": "^4.0.0",
    "gulp-load-plugins": "^1.5.0",
    "gulp-rename": "^1.2.2"
  },
  "optionalDependencies": {
    "less": "^3.0.4"
  }

@hawkerboy7
Copy link

hawkerboy7 commented May 31, 2018

I have the same issue descibed by @xinglie upgrading from less@2.7.3.

The workaround provided by @tiodot did not seem to work for me (tried: less@3.0.0 and less@3.0.4).
Also using the require('less').render() workaround provided by @seven-phases-max didn't do the trick :(
Are there maybe more suggestions? :)

@xvilo
Copy link

xvilo commented Jun 1, 2018

Also affected with this :(

CITguy pushed a commit to HelixDesignSystem/helix-ui that referenced this issue Jun 14, 2018
Less 3.x has a bug that prevents the correct CSS from being generated
when the `less` object in node is reused and the entry point hasn't
changed (CSS changes only exist in `@import`ed files).

The first compile works as expected, but subsequent compiles are broken.

This is causing issues with our build pipeline when updating styles
and the development server is running. Currently, you have to restart
the development server to see the updated styles.

See less/less.js#3185
@hawkerboy7
Copy link

Hi, though I am not sure what I did differently the workaround @tiodot provided DOES work for me now!
I tried it again and I must have made a mistake somewhere in the code.
(using less@3.0.4).
Thanks @tiodot !

@microcodebase
Copy link

Thanks @tiodot

@matthew-dean
Copy link
Member

@tiodot @hawkerboy7 @TigersWay Does this branch resolve the issue? If so, I'll make a PR - please check this out - https://github.com/matthew-dean/less.js/commits/cache-modified

@TigersWay
Copy link

Just did checks in 2 clearly different projects, commenting out @tiodot great patch inside package.json, and it seems to be working perfectly!!

  "optionalDependencies": {
    "less": "github:matthew-dean/less.js#cache-modified"
  },

@nexces
Copy link

nexces commented Jun 17, 2018

@matthew-dean works for me!

@hawkerboy7
Copy link

@matthew-dean Yes it has resolved the issue! PR to the rescue!! :)

@matthew-dean
Copy link
Member

@tiodot @hawkerboy7 @TigersWay Cool, the nice thing is, you should get slightly faster Less compiling with a warm cache (a 3.x feature), so it's preferable to have it fixed; otherwise I would have suggested taking it out. Will do a PR.

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