Page MenuHomePhabricator

ext.visualEditor.desktopArticleTarget.init errors if I call jQuery in global.js
Closed, InvalidPublic1 Estimated Story Points


I found if I call jQuery in global.js, ext.visualEditor.desktopArticleTarget.init may fail on Chinese Wikipedia. When it fails, my codes and gadgets on zhwp won't load anymore. Here is the error message:

Exception in module-execute in module ext.visualEditor.desktopArticleTarget.init:
Error: Bad constructor arguments Error: Bad constructor arguments
    at Uri (eval at <anonymous> (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:4), <anonymous>:127:715)
    at HTMLAnchorElement.eval (eval at <anonymous> (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:4), <anonymous>:438:45)
    at Function.each (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:5)
    at jQuery.fn.init.each (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:2)
    at HTMLDocument.eval (eval at <anonymous> (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:4), <anonymous>:438:21)
    at fire (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:45)
    at Object.add [as done] (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:45)
    at jQuery.fn.init.jQuery.fn.ready (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:49)
    at jQuery.fn.init (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:41)
    at jQuery (/w/load.php?debug=false&lang=zh-tw&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1ljmhq7:1)

However, it doesn't always fail. Sometimes everything is fine.

I replaced global.js with


Errors still existed.

When I remove everything about jQuery in global.js, no errors occured.

Now I'm using

mw.loader.using('ext.visualEditor.core').always(function () {

in global.js. No errors then.

Maybe T156899: VE should wait for global.js before init or T156346: VE plugins from user scripts suffer from race condition?

Other information:

  1. I use Firefox and Chrome
  2. While I'm finding errors, I disabled other gadgets and features on zhwp except VE and new wikitext editor.

Event Timeline

vjudge404 created this task.Apr 2 2017, 4:31 AM
Restricted Application added subscribers: Cosine02, Aklapper. · View Herald TranscriptApr 2 2017, 4:31 AM
Jdforrester-WMF triaged this task as Medium priority.Apr 4 2017, 7:22 PM
Jdforrester-WMF set the point value for this task to 1.
Jdforrester-WMF moved this task from To Triage to TR1: Releases on the VisualEditor board.
Jdforrester-WMF added a subscriber: Jdforrester-WMF.

[I don't see how this is specific to Chinese wikis.]

Interesting bug – possibly our assumptions about jQuery availability before anything else is loaded is broken?

This comment was removed by vjudge404.
Krinkle added a subscriber: Krinkle.EditedApr 5 2017, 5:17 PM

Interesting bug – possibly our assumptions about jQuery availability before anything else is loaded is broken?

Most unlikely.

Logical requirement:

  • global.js from Meta-Wiki is loaded by using mw.loader.load("//\u0026lang=en\u0026modules=ext.globalCssJs.user\u0026only=scripts\u0026skin=vector\u0026user=***\u0026version=***");});
  • mw.loader.load() itself uses jQuery. Without jQuery, global.js would not have been loaded at all. If it arrives and has the opportunity to run any code at all, then its content cannot affect whether or not jQuery would have been loaded.

Execution order:

  • global.js from Meta-Wiki is loaded by using mw.loader.load("//");}); inside RLQ.push inside <script>.
  • RLQ is processed by startup.js after it arrives and the "jquery+mediawiki" request is completed. If this was somehow processed too early, then mw.loader would also be undefined.

More likely is that another script from @vjudge404 or zhwiki is causing jQuery to be broken or redefined somehow. I haven't been able to reproduce this, though.

Jdforrester-WMF changed the task status from Open to Stalled.Apr 5 2017, 5:35 PM

Stalled waiting on further information or reproduction steps.

Sorry for not replying. It's not related to VE and it's possibly something wrong on zhwp because I can't get error messages on other projects.

Krinkle removed a subscriber: Krinkle.May 25 2017, 3:18 PM
Krinkle closed this task as Invalid.Jan 2 2018, 8:17 PM
Krinkle added a project: Performance-Team.
Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptJan 2 2018, 8:17 PM