Page MenuHomePhabricator

ResourceLoader: Remove custom LESS functions
Closed, ResolvedPublic

Description

I think it was a design flaw that we went ahead with implementing php-land functions at all. It was a questionable experiment, but we know better now and I think we should admit that and phase it out ASAP.

This brings three main problems:

  1. Decreased compatibility; (can't easily compile it with lessjs without porting the functions over and keeping in sync).
  2. Extra maintenance; (when we switch lessphp implementations or upgrade, these will need updating).
  3. Separation of concerns and flow control; (embedding is supposed to be part of CSSMin and run *after* CSSJanus; doing it in LESS before it even turns to CSS disrupts this).

Problem #3 causes bugs like bug 66091 (T68091), where in Less files certain things don't get flipped properly by CSSJanus because it jumps the gun on mapping things to files on disk and reading them.

I think we should deprecate the less embed() function and instead ensure the /* @embed */. This provides many benefits:

  • Reduced duplication.
  • Less output is easier to debug with (no embedded data uris[1]).
  • No maintenance overhead (and bugs like bug 66091) by having to keep its behaviour in sync with non-LESS files with regards to CSSJanus flipping.
  • Keeps minification restricted to CSSMin (which runs anyway, the only way it makes sense to start minifying or reading files from disk earlier is if we somehow phase out CSSMin entirely, which would be an interesting adventure of its own)

Version: 1.24rc
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=66091 T68091: ResourceLoaderLESSFunctions::embed does not support CSSJanus flipping for RTL, affecting .background-image-svg() and others
https://bugzilla.wikimedia.org/show_bug.cgi?id=54673 T56673: LESS compiler should preserve the position of CSSMin / CSSJanus annotations

Details

Reference
bz67368

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 3:41 AM
bzimport set Reference to bz67368.

Note that OOjs UI, for example, as being a standalone project, never used the 'embed()' function because we use its compiled distribution file which is already CSS (compiled by lessjs via Grunt).

And yet it has no impact on its performance because /* @embed */ degrade gracefully for third parties and is still picked by CSSMin when MediaWIki loads oojs-ui.css.

This is not a coincidence, CSSMin was designed this way on purpose and Less kind of broke that paradigm.

This loosely depends on bug 54673. I don't think we have to block on it (it mostly works already) but there's weird edge cases where Less messes up the comments and those are hard to detect so ideally it would "just work" before we give that up.

(In reply to Krinkle from comment #2)

This loosely depends on bug 54673. I don't think we have to block on it (it
mostly works already) but there's weird edge cases where Less messes up the
comments and those are hard to detect so ideally it would "just work" before
we give that up.

My understanding is those weird edge cases are exactly why the custom functions were introduced, so it does sound like a blocker to me.

Change 161245 had a related patch set uploaded by Bartosz Dziewoński:
Fix CSSJanus flipping in LESS mixins and remove broken custom LESS functions

https://gerrit.wikimedia.org/r/161245

Change 161751 had a related patch set uploaded by Krinkle:
Fix CSSJanus flipping in LESS mixins and remove broken custom LESS functions

https://gerrit.wikimedia.org/r/161751

Change 161245 merged by jenkins-bot:
Fix CSSJanus flipping in LESS mixins and remove broken custom LESS functions

https://gerrit.wikimedia.org/r/161245

Change 161751 merged by jenkins-bot:
Fix CSSJanus flipping in LESS mixins and remove broken custom LESS functions

https://gerrit.wikimedia.org/r/161751