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

How to tell when less is done processing ? #283

Closed
agersant opened this issue May 29, 2011 · 20 comments
Closed

How to tell when less is done processing ? #283

agersant opened this issue May 29, 2011 · 20 comments

Comments

@agersant
Copy link

Hi.

I'm working with jQuery and I'm used to running javascript code as soon as the DOM is ready. The funny bit is that my js is performing operations which involve reading some DOM elements' css attributes. However, it turns out the js may or may not run after Less has done his job.
The consequence is that oftentimes, my js will read values before they are set - thus leading to unexpected behaviors.

My question is simple : is there a way (event, flag...anything) to tell when the less processing is complete and execute JS code after ?

@ttfkam
Copy link
Contributor

ttfkam commented Aug 6, 2011

Sounds like a good idea.

@harobed
Copy link

harobed commented Sep 22, 2011

Good idea !

@rulatir
Copy link

rulatir commented Jul 19, 2012

Upvoted!

@rulatir
Copy link

rulatir commented Jul 28, 2012

This is really, really, really BADLY needed in order to be able to avoid FOUC!

@lukeapage
Copy link
Member

it is not recommended to run less.js in the browser in production.

for development set a timeout for x milliseconds.. wouldnt that be good enough?

@rulatir
Copy link

rulatir commented Jul 29, 2012

it is not recommended to run less.js in the browser in production.

Why not, and what is recommended instead if one does rely on
javascript()? Also, isn't the unavailability of processing completion
notification one of the reasons why it is not recommended,
circular-logically?

Szczepan Hołyszewski

@lukeapage
Copy link
Member

Its not recommended because its bad for performance and only runs correctly on a small set of (modern) browsers. You are right that there are also several bugs that make it more difficult.

Instead, compile the less before hand in node - This support javascript - unless you are accessing variables on the page? In which case it depends on your serverside setup and what variables you use, but it might be better to try and move that serverside.

There are cases where it makes sense to use less.js browser side - for instance in a theme editor where a admin user is editing things on the fly.. but then for more generic users it would be better to compile and cache serverside.

So it does depend on your situation and I'm not saying this feature request will never get added, just that it is low priority.

@velosipedist
Copy link

Why not to just add stylesheet node DOM event firing& It is very easy to implement and will not hit the performance.

But it wil allow to catch stylesheet refreshing (especially important in watch mode) for any purposes.

For example, i'm writing ajax-based Less stylesheets updater, cause im'not able to install Node.js on hosting.
Just want to have ability to update stylesheet changes without any offline compilers, right with latest less.js version.

@roelvanduijnhoven
Copy link
Contributor

My use-case IS an theme editor, and so I would find this highly useful!

@lukeapage
Copy link
Member

@roelvanduijnhoven happy to accept pull requests

@roelvanduijnhoven
Copy link
Contributor

Maybe I will look into this.

The way I fix this at the moment is to poll every few miliseconds until a specific css style has been loaded on a DOM element. Although this works in practise this is 1) a nasty hack and 2) can break in theory because not all styles could have been loaded at that moment in time.

@cphill02
Copy link

It would be very nice and pretty standard to have a callback function for after LESS is done processing.

@lukeapage
Copy link
Member

I agree. That is why it is labeled ReadyForImplementation and has a milestone of the next release.. it is just waiting for someone to implement..

@akashivskyy
Copy link

👍

@levithomason
Copy link
Contributor

I'd like to jump in on this. Is any one working on this yet? I've browsed the PRs and didn't see it. I also didn't see it on the 2.0.0 release checklist #1902.

@lukeapage do you know if there is somewhere I can contribute to this feature or if I need to start it from scratch? Thanks!

@lukeapage
Copy link
Member

Hi,

Good news, thanks. 1. Branch from the v2 branch. 2. Consider we want to
make the browser code more flexible and not just add stuff in. That being
said, this needs a new less thing.

How about a promise on the less object which is resolved after the initial
scan?
Look in less-browser/index.js
We use a promise polyfill already in v2... See render.js or file manager.

Long term (not necessary for your pull request) we can make refresh return
a promise and just set less.xxx to be that promise for the first scan..

Open to discuss alternatives, am sketching this out from a mobile phone...

@levithomason
Copy link
Contributor

Awesome. Being there is room for jumping in I'm gonna branch v2, grokk the issue and your comments better, and come back with some ideas. Looks like there have been a few changes since I last perused the source 1.7.0 ;)

That being said, this needs a new less thing.

Not sure what is meant by 'thing' here though.

@lukeapage
Copy link
Member

That being said, this needs a new less thing.
Not sure what is meant by 'thing' here though.

Sorry I know it wasn't clear - I mean that its easy to keep adding events and options to less - I'd rather refactor what we have to make it able to be used in a more flexible way than to keep adding options.

And I'm saying that exposing an extra field (the thing :)) on the less object is necessary for this and not too bad if we consider further improvements.

@levithomason
Copy link
Contributor

Moving conversation on solutions to PR #2226.

@lukeapage
Copy link
Member

released in v2 beta 2

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

10 participants