Page MenuHomePhabricator

Limit preloading of CodeMirror modules
Closed, ResolvedPublic

Description

CodeMirror uses the BeforePageDisplay hook, and checks if the action is edit or submit, along with other conditions (Hooks::shouldLoadCodeMirror). It's unclear why this was used over the EditPage::showEditForm:initial hook. As a result, the CodeMirror module gets predelivered even when it isn't used, such as on read-only pages.

Browsing to a page you are unable to edit…

Before r1007746, with $wgCodeMirrorV6 = false;:

> mw.loader.getState( 'ext.CodeMirror.WikiEditor' )
"ready"

and afterwards:

> mw.loader.getState( 'ext.CodeMirror.WikiEditor' )
"registered"

which is what we want.

The module is also loaded pretty much anywhere action=edit is and CodeEditor isn't, so it could unnecessarily be in the startup module in a variety of scenarios. To further address this, we should check the content model to make sure it is one that is supported (as of the time of writing, only wikitext).

Possible risk

  • It is possible that some gadget or script out there is assuming CodeMirror is available upfront, when it won't be following this task. A Global Search for CodeMirror.fromTextArea shows most usages already require the ext.CodeMirorr.WikiEditor module (or the CM library directly), so hopefully we won't see much breakage. Nonetheless we should monitor for an increase of JS errors.

Acceptance criteria

  • ext.CodeMirror.WikiEditor (or ext.CodeMirror.v6.WikiEditor in the case of CM6) should only be "ready" where CodeMirror is actually usable
  • Extensions that have content models needing CodeMirror should register a CodeMirrorContentModels. In our cluster, I *think* this only includes ProofreadPage (r1007747)

QA Results - Beta

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 1007746 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] Hooks: further limit where CodeMirror RL modules are loaded

https://gerrit.wikimedia.org/r/1007746

Change 1007747 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/ProofreadPage@master] extension.json: register 'proofread-page' in CodeMirrorContentModels

https://gerrit.wikimedia.org/r/1007747

Change 1007746 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Hooks: further limit where CodeMirror RL modules are loaded

https://gerrit.wikimedia.org/r/1007746

Change 1007747 merged by jenkins-bot:

[mediawiki/extensions/ProofreadPage@master] extension.json: register 'proofread-page' in CodeMirrorContentModels

https://gerrit.wikimedia.org/r/1007747

Leaving to QA's judgement whether this needs testing. It was intentionally +2'd to ride this week's train, so if there are any unwanted side effects, we should know about them come Thursday. See the "Possible risk" in the task description.

I'll be monitoring prod for relevant errors starting tomorrow.

@MusikAnimal Codemirror seems to be working fine as seen from some of the screenshots below. There are some toggle on/off issues which T360075: CodeMirror6: WikiEditor toolbar buttons cease to function when CodeMirror toggled on/off more than once was created. I also added the article placement issue while toggling, just in case the previous task doesn't fix it. Other than that, I will move this to Done. Thanks for all your work!

Status: ✅PASS
Environment: Beta: 1.42.0-alpha (7e58353)
OS: macOS Sonoma 14.4
Browser: Chrome 122, Firefox 123, Safari 17.3, Edge 122
Skins. Vector 2022, Vector 2010, Minerva, Monobook, Timeless
Device: MBA M2
Emulated Device:: n/a
Test Links:
https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Dog&action=edit
https://he.wikipedia.beta.wmflabs.org/w/index.php?title=%D7%A2%D7%9E%D7%95%D7%93_%D7%A8%D7%90%D7%A9%D7%99&action=edit
https://en-rtl.wikipedia.beta.wmflabs.org/w/index.php?title=Main_Page&action=edit
https://simple.wikipedia.beta.wmflabs.org/w/index.php?title=Duke_Nukem_3D&action=edit

✅AC1: https://phabricator.wikimedia.org/T359206

BetaSimpleHeEn-RTL
2024-03-18_14-29-06.png (889×1 px, 273 KB)
2024-03-18_14-48-19.png (1×2 px, 370 KB)
2024-03-18_14-41-18.png (1×2 px, 223 KB)
2024-03-18_14-45-00.png (1×2 px, 257 KB)

❓Issue that may be related to T360075: CodeMirror6: WikiEditor toolbar buttons cease to function when CodeMirror toggled on/off more than once but adding this just in case since it's a different issue.

Article placement when toggling Codemirror more than once

ChromeSafari