Last modified: 2014-09-28 12:26:23 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T47229, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 45229 - OutputPage should not change order of stylesheet modules added by addModuleStyles
OutputPage should not change order of stylesheet modules added by addModuleSt...
Status: PATCH_TO_REVIEW
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
unspecified
All All
: Low enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
: 69159 (view as bug list)
Depends on:
Blocks: 66508
  Show dependency treegraph
 
Reported: 2013-02-21 14:14 UTC by Daniel Friesen
Modified: 2014-09-28 12:26 UTC (History)
6 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Daniel Friesen 2013-02-21 14:14:33 UTC
ResourceLoader sorts the modules for stylesheets added with addModuleStyles alphabetically ignoring dependencies.

In other words if you create the module 'a' and make it depend on the module 'b'. And then do `$out->addModuleStyles( 'b' ); $out->addModuleStyles( 'a' );`. ResourceLoader will load 'a' first and then load 'b', even though both the dependencies and addModuleStyles say that's wrong.

Skins use addModuleStyles to add skin styles to the page. The setupSkinUserCss was crafted previously so that addStyle could be used in the correct order by overriding the function and using parent::setupSkinUserCss at the right spots. And this works for subskins too since they can let the parent skin add it's styles before adding their own styles. However the alphabetical sorting done by RL goes and undoes any precise ordering required by that.

This is problematic for the creation of subskins. If you create a 'skin.foo' that depends on 'skin.vector' and setup setupSkinUserCss properly RL will go and put skin.vector after your 

The only reason every skin isn't already broken by the shared styles is that 'mediawiki.legacy.' alphabetically sorts before 'skin.'. If we fixed that and started using 'skins.common.' some skins could start to break.

Also note that most skins use mediawiki.legacy.shared and mediawiki.legacy.commonPrint which are not added by any core or third party skin to the dependency setup of the skin's module. So even if we fix this to not sort things before the things they depend on it would be best to make sure we also fix it to take addModuleStyles into account.

The ideal situation of course is to fix addModules to know that some modules should not be loaded by JS (another key on the module registration) and just use addModules inside of initPage, deprecating setupSkinUserCss for anything besides addStyle usage (eg: IE stylesheets) and old skin compatibility.
But we have skins that use addModuleStyles right now so we'll need to fix this bug at minimum for compatibility.
Comment 1 Krinkle 2013-02-22 21:36:58 UTC
There may be a way to address this, but in general you shouldn't use addModuleStyles and other mw.loader-circumventing methods in OutputPage.

They don't resolve dependencies, so why should they do use dependency information for the order?

The easiest improvement may be to keep them in order of addition (simply not alphabetise them).
Comment 2 Krinkle 2013-02-22 21:38:24 UTC
(moving out of ResourceLoader component as this is not (yet) related to the framework itself, but how MediaWiki's OutputPage (ab)uses it by calling it's entry point directly).
Comment 3 Daniel Friesen 2013-02-22 22:54:49 UTC
(In reply to comment #1)
> There may be a way to address this, but in general you shouldn't use
> addModuleStyles and other mw.loader-circumventing methods in OutputPage.

addModules loads stylesheets via JavaScript. This is absolutely unacceptable for the css loaded by skins. Hence addModuleStyles has been used from the start.

And this is a problem for the entire interface, not the installer.
Comment 4 Krinkle 2013-02-22 23:44:45 UTC
(In reply to comment #3)
> (In reply to comment #1)
> > There may be a way to address this, but in general you shouldn't use
> > addModuleStyles and other mw.loader-circumventing methods in OutputPage.
> 
> addModules loads stylesheets via JavaScript. This is absolutely unacceptable
> for the css loaded by skins. Hence addModuleStyles has been used from the
> start.
> 
> And this is a problem for the entire interface, not the installer.

I agree that's unacceptable for the skin. However if there's no dynamic client scripting involved, it means no dependencies can be resolved since we don't do that server side (not yet anyway).

So in the current system, addModuleStyles doesn't (nor claims to) support dependencies. It adds that one module as a raw stylesheet to the page.

As a short term fix it may help (not saying it is pretty, but it may improve the situation) to at least preserve the order in which the addModuleStyles() calls occurred, as generally these sort of things match execution order.

e.g. {
  parent::myMethod(); // adds module
  $out->addModuleStyles( .. );
}
Comment 5 Krinkle 2014-02-20 04:41:21 UTC
(see bug 61577)
Comment 6 Gerrit Notification Bot 2014-05-16 22:00:42 UTC
Change 133843 had a related patch set uploaded by Daniel Friesen:
Do not sort modules alphabetically

https://gerrit.wikimedia.org/r/133843
Comment 7 Krinkle 2014-05-16 22:46:24 UTC
Note that one reason to do sort them alphabetically is to share cache between pages. This is why mw.loader.load calls outputted by the server as well as the actual http requests made my mw.loader always sort alphabetically, since implementation ensures proper execution order.

When code adds things using addModuleStyles that aren't order-sensitive per se, this keeps them consistently in the same order regardless of whether two pieces of code execute in a slightly different order (e.g. as result of refactoring in the caller, or, changing the order in which hooks are registered when you reorder things in LocalSettings.php, etc.).

That can all lead to inconsistencies (e.g. if a module is loaded on a Special page via hook, and in the parser on regular pages, if those happen in different orders then they wouldn't consistently load after or before the skin).

So I can imagine it may be interesting to investigate the possibility of keeping the forced sort with the option to perhaps hoist important ones in a fixed order.

Anyway, that opens another can of worms and an arms race of sorts, so let's not for now :)
Comment 8 Daniel Friesen 2014-05-16 22:48:21 UTC
(In reply to Krinkle from comment #7)
> So I can imagine it may be interesting to investigate the possibility of
> keeping the forced sort with the option to perhaps hoist important ones in a
> fixed order.

;) Like a dependency system to declare which ones need to be loaded first?
Comment 9 Bartosz Dziewoński 2014-06-12 16:05:58 UTC
It seems to be that even a very rudimentary broken-by-design dependencies support in addModuleStyles() (bug 61577) would be a better fix for this than preserving the call order (or no fix at all). That said, I'd support just preserving the order too.

(In reply to Daniel Friesen from comment #8)
> (In reply to Krinkle from comment #7)
> > So I can imagine it may be interesting to investigate the possibility of
> > keeping the forced sort with the option to perhaps hoist important ones in a
> > fixed order.
> 
> ;) Like a dependency system to declare which ones need to be loaded first?

Yeah, we really shouldn't create a separate system for dependencies. Sure, we could add a key like 'stylesAfter' to ResourceLoaderFileModule that would effectively implement half-asses dependency support, but why do that if we already implemented dependencies once?
Comment 10 Bartosz Dziewoński 2014-08-28 20:24:41 UTC
*** Bug 69159 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links