Page MenuHomePhabricator

TypeError: Cannot read properties of undefined (reading '$ui') / TypeError: this.context is undefined
Closed, ResolvedPublicPRODUCTION ERROR

Description

3471 errors in last 7 days, spiking in 1.45.0-wmf.3
https://logstash.wikimedia.org/goto/ac05fcc6cbe510499f8129d6d69f670b
Highest error by volume currentlly.

Error 1

	at RealtimePreview.createToolbarButton  https://en.wikipedia.org/w/load.php?lang=dga&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=1my1m:4:155
at new RealtimePreview  https://en.wikipedia.org/w/load.php?lang=dga&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=1my1m:2:890
at eval  https://en.wikipedia.org/w/load.php?lang=dga&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=1my1m:1:371
at Object.add  https://en.wikipedia.org/w/load.php?lang=dga&modules=mediawiki.base&skin=vector-2022&version=123uw:4:326
at realtimepreview/init.js  https://en.wikipedia.org/w/load.php?lang=dga&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=1my1m:1:210
at runScript  https://en.wikipedia.org/w/load.php?lang=dga&modules=startup&only=scripts&raw=1&skin=vector-2022:11:748
at Array.<anonymous>  https://en.wikipedia.org/w/load.php?lang=dga&modules=startup&only=scripts&raw=1&skin=vector-2022:12:504
at flushCssBuffer  https://en.wikipedia.org/w/load.php?lang=dga&modules=startup&only=scripts&raw=1&skin=vector-2022:4:385

Error 2

TypeError: this.context is undefined

at realtimepreview/RealtimePreview.js/RealtimePreview.prototype.createToolbarButton https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=iv8g7:4:142
at RealtimePreview https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=iv8g7:2:890
at realtimepreview/init.js/< https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=iv8g7:1:371
at add https://en.wikipedia.org/w/load.php?lang=en&modules=mediawiki.base&skin=vector-2022&version=14zm8:4:326
at realtimepreview/init.js https://en.wikipedia.org/w/load.php?lang=en&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=iv8g7:1:210
at runScript https://en.wikipedia.org/w/load.php?lang=en&modules=startup&only=scripts&raw=1&skin=vector-2022:11:758
at execute/cssHandle/< https://en.wikipedia.org/w/load.php?lang=en&modules=startup&only=scripts&raw=1&skin=vector-2022:12:504at flushCssBuffer https://en.wikipedia.org/w/load.php?lang=en&modules=startup&only=scripts&raw=1&skin=vector-2022:4:385

Steps to replicate the issue (include links if applicable):

What happens?:

What should have happened instead?:

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Restricted Application changed the subtype of this task from "Bug Report" to "Production Error". · View Herald TranscriptJun 2 2025, 3:41 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change #1153443 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/extensions/WikiEditor@master] Guard against WikiEditor context not being available

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

I haven't been able to replicate this yet, but we can add a check for the WikiEditor context and not load Realtime Preview if it's not there for whatever reason. Is that just hiding the issue? Maybe. :(

Change #1153443 merged by jenkins-bot:

[mediawiki/extensions/WikiEditor@master] Guard against WikiEditor context not being available

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

Okay I've found at least a bit more of a reproduction, and the above . If you add the following to common.js (to enable WikiEditor on the upload description field), you can get the error:

mw.loader.using( 'ext.wikiEditor' ).then( () => {
	mw.addWikiEditor( $( '#wpUploadDescription' ) );
} );
Uncaught TypeError: this.context is undefined
    createToolbarButton http://localhost/w/load.php?lang=en-gb&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=19s4j:4
    RealtimePreview http://localhost/w/load.php?lang=en-gb&modules=ext.wikiEditor.realtimepreview&skin=vector-2022&version=19s4j:2

There are broader issues when adding it to a alternate textarea, which are tracked in T362356.

@Samwilson I'm not seeing this error in the logs: https://logstash.wikimedia.org/goto/269acbca2ce078183e2f73d7e773999e (23rd of June was last report)
Did the error message / stack trace change of did your patch above fix it?

That's good that it's not happening any more, but my memory is that the patch here didn't actually fix it in all cases. https://gerrit.wikimedia.org/r/c/mediawiki/extensions/WikiEditor/+/1153589 fixed a similar issue but that was merged on 27th of June.

I guess this can be closed. Other bugs can be fixed as part of T362356.

Closing per last comment.