Page MenuHomePhabricator

Use $() instead of mw.hook( 'wikipage.content' ).add() in ext.toctree.js
Closed, InvalidPublic


In the last line of the javascript library ext.toctree.js, $( init ) should be used instead of mw.hook( 'wikipage.content' ).add( init ).

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 7 2019, 5:14 PM

Of course, the global function call is to be adapted to use jQuery like ( function ( $ ) { ... } ( jQuery ) );

Krinkle added a subscriber: Krinkle.EditedApr 7 2019, 5:32 PM

What is the problem you are experiencing and wanting to solve?

See 78d9e3bcf63eb /

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

TocTree is correct as far as I see. Maybe there is a race-condition somewhere else.

When I load a random page like 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 that lead to race conditions. But the extension TocTree is not the root cause.

Fomafix closed this task as Invalid.Apr 9 2019, 5:07 AM

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 I fix an failure in Maps (Kartographer) which causes the exception in T220308#5091821.

On the JavaScript code in 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 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 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 contains 92 elements with class mw-kartographer-maplink:

$( '.mw-kartographer-maplink[mw-data="interface"]', '.mw-body' ).length // 92

After loading 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 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

Fomafix claimed this task.Apr 9 2019, 8:13 PM
Fomafix removed a project: Patch-For-Review. is merged. Please test again when it is deployed.

I can not find any JavaScript errors while loading of anymore.