Page MenuHomePhabricator

Possible race condition in gallery javascript code
Closed, InvalidPublic


Every now and then i get a TypeError on my wikis "TypeError: $.debounce is not a function". I tracked it down to the gallery code:

			if ( !bound ) {
				bound = true;
				$( window )
					.resize( $.debounce( 300, true, handleResizeStart ) )
					.resize( $.debounce( 300, handleResizeEnd ) );

which can be seen here:;c355cc53ab6d36498aede46a016521d7bd8ce071$263

Apparently in some cases the gallery javascript loads before the debounce jquery plugin is loaded, so that should probably be put into some kind of dependency. I tested it in 1.28.2 but that code hasn't changed since for all i know.


Event Timeline

Restricted Application added a project: Multimedia. · View Herald TranscriptSep 12 2017, 10:49 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
FO-nTTaX updated the task description. (Show Details)Sep 12 2017, 10:49 PM

The dependency is already correctly specified:;c355cc53ab6d36498aede46a016521d7bd8ce071$1643

Are you sure this code is the source of the error? I found an undeclared dependency on this code in another module, resources/src/mediawiki/htmlform/htmlform.Checker.js – fixing that in Perhaps that is actually your issue?

Ramsey-WMF moved this task from To Do to Needs QA on the Multimedia-Team-Working-Board board.
Ramsey-WMF moved this task from Untriaged to Next up on the Multimedia board.
Ramsey-WMF moved this task from Next up to Triaged on the Multimedia board.

@Ramsey-WMF Should this have a priority set?

Ramsey-WMF triaged this task as Medium priority.Sep 19 2017, 4:44 PM

@FO-nTTaX Interesting. I can reproduce the issue on , but only when I disable my ad blocker.

Actually, nevermind that, I can reproduce with ad blocker too, it just doesn't happen every time.

Yeah, the fact that it doesn't happen everytime is why i titled it as possible race condition. I don't use an adblocker/scriptblocker myself, so I can only speak about a non-adblocker state.

Krinkle added a comment.EditedSep 19 2017, 9:03 PM

@FO-nTTaX I was able to reproduce it, and again with a breakpoint at the offending line in

Console checking:
$.debounce is indeed undefined.
$ is indeed the jQuery loaded by MediaWiki
Module did specify dependency.
Dependency did get loaded.
Definition of dependency.
Note how it attaches the method to window.jQuery.
Definition of window.jQuery is not from MediaWiki, but skins.liquiflow
  1. MediaWiki loads jQuery.
  2. MediaWiki loads jquery.throttle-debounce, skins.liquiflow and
  3. Module skins.liquiflow includes another copy of jQuery, thus re-defining the variable jQuery to a plain copy without any of the added properties.
  4. Module jquery.throttle-debounce adds property debounce to the new jQuery object (because it bypassed the scoped $ and jQuery references by looking up directly from window)
  5. Module looks for debounce in the main jQuery object (the original).

The problem is that the Liquiflow module is loading a second copy of jQuery, which is unsupported. The moment a second copy is loaded, the previous version is overwritten and with it, any extensions/plugins/settings also get dereferenced.

Krinkle closed this task as Invalid.Sep 19 2017, 9:08 PM
Krinkle moved this task from Inbox to Backlog on the MediaWiki-ResourceLoader board.

@FO-nTTaX I hope the above helps you solve the problem (by removing scripts/jquery.min.js from the skins.liquiflow module definition in LiquiFlow). I'll close this task as invalid given it isn't a problem in MediaWiki or ResourceLoader.

Ah thanks so much, I've spent too long looking at this so i guess I missed that T_T