In the last line of the javascript library ext.toctree.js, $( init ) should be used instead of mw.hook( 'wikipage.content' ).add( init ).
Description
Details
Subject | Repo | Branch | Lines +/- | |
---|---|---|---|---|
Handle the case that getMapData returns null | mediawiki/extensions/Kartographer | master | +3 -0 |
Related Objects
Event Timeline
Of course, the global function call is to be adapted to use jQuery like ( function ( $ ) { ... } ( jQuery ) );
What is the problem you are experiencing and wanting to solve?
See 78d9e3bcf63eb / https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/TocTree/+/307687/.
In case of a runtime errrors mw.hook() is sometimes not working. This can be overcome by using jQuery.ready function.
Sometimes a runtime error (TypeError) occurs but not in any case. This error prevents proper function of mw.hook().
Console log:
TypeError: data is null[Learn More] load.php:93:1378 module.exports</</< https://de.wikivoyage.org/w/load.php:93:1378 .each https://de.wikivoyage.org/w/load.php:165:859 jQuery.prototype.each https://de.wikivoyage.org/w/load.php:163:925 module.exports</< https://de.wikivoyage.org/w/load.php:93:1213 jQuery.Callbacks/fire https://de.wikivoyage.org/w/load.php:206:897 jQuery.Callbacks/self.fireWith https://de.wikivoyage.org/w/load.php:208:114 mw.hook</</<.fire https://de.wikivoyage.org/w/load.php:712:567 <anonymous> https://de.wikivoyage.org/w/load.php:764:1275 resolve/</mightThrow https://de.wikivoyage.org/w/load.php:209:848 resolve/</process< https://de.wikivoyage.org/w/load.php:210:516
TocTree is correct as far as I see. Maybe there is a race-condition somewhere else.
When I load a random page like https://de.wikivoyage.org/wiki/Arnsberg I can see no error. But when I throttle the requests in Firefox then I get
ReferenceError: jQuery33109765425919619954_1554750849522 is not defined
I can see it often (30-40%) when calling the article about Ko Lanta. TOC remains open and the console shows some errors (see above). I use the firefox as well.
There are some missing dependencies in https://de.wikivoyage.org/ that lead to race conditions. But the extension TocTree is not the root cause.
I just got also the error message above. This error come from extension Maps (Kartographer). As visible result the TocTree gets not executed. But this is not a fault of TocTree.
Change 502396 had a related patch set uploaded (by Fomafix; owner: Fomafix):
[mediawiki/extensions/Kartographer@master] Handle the case that getMapData returns null
With https://gerrit.wikimedia.org/r/502396 I fix an failure in Maps (Kartographer) which causes the exception in T220308#5091821.
On the JavaScript code in https://de.wikivoyage.org/ there are some dependencies on modules missing. This leads to a race condition is the code fail. This may also lead to some error, which causes TocTree gets not fired.
User scripts on de.wikivoyage.org only seldom use external modules. The dependencies are realized with mw.loader.using()/require() calls. Maybe there are missing dependencies in Kartographer. Some time ago we found such a failure (T197655).
In https://de.wikivoyage.org/wiki/MediaWiki:ListingEditor.js a dependency on module mediawiki.api is missing because it uses mw.Api(). I identified this with a throttled network connection in Firefox.
I found the reason for the race condition:
The HTML of https://de.wikivoyage.org/wiki/Ko_Lanta contains 92 elements with class mw-kartographer-maplink:
$( '.mw-kartographer-maplink[mw-data="interface"]', '.mw-body' ).length // 92
After loading https://de.wikivoyage.org/wiki/MediaWiki:GeneralChanges.js there are 118 elements with class mw-kartographer-maplink. The 26 new elements have no attribute mw-data="interface":
$( '.mw-kartographer-maplink', '.mw-body' ).length // 118
The race condition is also between Maps (Kartographer) and https://de.wikivoyage.org/wiki/MediaWiki:GeneralChanges.js
https://gerrit.wikimedia.org/r/502396 should fix this problem because now it ignores elements without mw-data="interface" instead of raising a runtime error.
Change 502396 merged by jenkins-bot:
[mediawiki/extensions/Kartographer@master] Handle the case that getMapData returns null
https://gerrit.wikimedia.org/r/502396 is merged. Please test again when it is deployed.
I can not find any JavaScript errors while loading of https://de.wikivoyage.org/wiki/Arnsberg anymore.