Through a quite complex customization of skin & color theme variables, I have obtained a case where style.less.vm (style.css) is added in the less compilation cache with one color theme as a key while the colors in it are actually the ones of another color theme.
After investigation, I found that: * when the compiled less resources are put in the cache, the key for the cache entry is built with the code from [CurrentColorThemeGetter.java#L86|https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-lesscss/xwiki-platform-lesscss-default/src/main/java/org/xwiki/lesscss/internal/colortheme/CurrentColorThemeGetter.java#L86] ** this code checks the color theme by only taking into account request.colorTheme and the current user's / preference (which fallsback on wiki color theme ) * however, this color theme that was detected like this is then never actually set when compiling the resource: the compute function here [AbstractCachedCompiler.java#L137|https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-lesscss/xwiki-platform-lesscss-default/src/main/java/org/xwiki/lesscss/internal/cache/AbstractCachedCompiler.java#L137], the compilation is responsible of fetching its own color theme. For XWiki resources (for example style.less.vm), this is done by colorThemeInit.vm . * thus, the cache key and the _actual_ color theme used by the cached css will only be in sync if the "current color theme" is detected in _exactly the same way_ by colorThemeInit.vm and by [CurrentColorThemeGetter.java#L86|https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-lesscss/xwiki-platform-lesscss-default/src/main/java/org/xwiki/lesscss/internal/colortheme/CurrentColorThemeGetter.java#L86] .
Thus, it's not actually possible to customize colorThemeInit.vm to make a different detection of the color theme, unless the CurrentColorThemeGetter.java is customized along with it. Failing to do so _can_ endup in a wrong association of a theme as a cache key with the colors. |
|