Page MenuHomePhabricator

TypeError: this.button is undefined / TypeError: Cannot read properties of undefined (reading 'isVisible')
Closed, ResolvedPublicPRODUCTION ERROR

Description

Two error messages with same stacktrace:

Error
normalized_message
TypeError: this.button is undefined
exception.trace
at realtimepreview/RealtimePreview.js/RealtimePreview.prototype.enableFeatureWhenScreenIsWideEnough https://pl.wikipedia.org/w/load.php?lang=pl&modules=ext.CodeMirror%2Ccharinsert%7Cext.CodeMirror.data%7Cext.wikiEditor.images%2Crealtimepreview%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.makeCollapsible.styles%7Cjquery.ui%7Cmediawiki.diff.styles%7Cmediawiki.language.specialCharacters%7Cmediawiki.page.preview%7Cmediawiki.template%2Cwidgets%7Cmediawiki.widgets.styles%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui.styles.icons-content%2Cicons-editing-advanced%2Cicons-editing-citation%2Cicons-editing-core%2Cicons-editing-list%2Cicons-editing-styling%2Cicons-media%2Cindicators&skin=vector&version=17gik:24:169
at dispatch https://pl.wikipedia.org/w/load.php?lang=pl&modules=ext.CodeMirror%2Ccharinsert%7Cext.CodeMirror.data%7Cext.wikiEditor.images%2Crealtimepreview%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.makeCollapsible.styles%7Cjquery.ui%7Cmediawiki.diff.styles%7Cmediawiki.language.specialCharacters%7Cmediawiki.page.preview%7Cmediawiki.template%2Cwidgets%7Cmediawiki.widgets.styles%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui.styles.icons-content%2Cicons-editing-advanced%2Cicons-editing-citation%2Cicons-editing-core%2Cicons-editing-list%2Cicons-editing-styling%2Cicons-media%2Cindicators&skin=vector&version=17gik:102:260
at add/elemData.handle https://pl.wikipedia.org/w/load.php?lang=pl&modules=ext.CodeMirror%2Ccharinsert%7Cext.CodeMirror.data%7Cext.wikiEditor.images%2Crealtimepreview%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.makeCollapsible.styles%7Cjquery.ui%7Cmediawiki.diff.styles%7Cmediawiki.language.specialCharacters%7Cmediawiki.page.preview%7Cmediawiki.template%2Cwidgets%7Cmediawiki.widgets.styles%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui.styles.icons-content%2Cicons-editing-advanced%2Cicons-editing-citation%2Cicons-editing-core%2Cicons-editing-list%2Cicons-editing-styling%2Cicons-media%2Cindicators&skin=vector&version=17gik:98:877
Impact
Notes

Event Timeline

Jdlrobson created this task.
Jdlrobson renamed this task from TypeError: this.button is undefined to TypeError: this.button is undefined / TypeError: Cannot read properties of undefined (reading 'isVisible').May 26 2022, 4:38 PM
Jdlrobson updated the task description. (Show Details)
Jdlrobson updated the task description. (Show Details)

I've not looked into it yet, but this might be because on plwiki Realtime Preview is loaded as a gadget rather than in the usual way.

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

[mediawiki/extensions/WikiEditor@master] Realtime preview: allow loading as a gadget

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

Change 804273 merged by jenkins-bot:

[mediawiki/extensions/WikiEditor@master] Realtime preview: allow loading as a gadget

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

dom_walden subscribed.

I loaded the WikiEditor/CodeEditor for pages in various namespaces on beta wikisource (where RTP is loaded as a gadget).

I did not see any errors in the browser console on Firefox. Nor were there any errors in beta's logstash.

However, it may be worth keeping an eye on the errors logs when this gets deployed to production.

Krinkle subscribed.

It appears this bug is still happening consistently on test2.wikipedia.org when resizing the window, e.g. at https://test2.wikipedia.org/w/index.php?title=Main_Page

I've confirmed that the above linked git commit has been merged and made it to production, including on this particular wiki.

The problem appears to be that this.button is undefined. I realize that's literally the native error message, but it seems genuine and expected, and not addressed by the commit in question.

The constructor is run on every page load, and sets up a global window event handler. This callback then makes reference to something this constructor has neither directly nor indirectly created, thus can be undefined.

In order to uphold the same separation of concerns that the realtime preview has today (that is, it leaves it up to WikiEditor to decide whether to invoke addToTolbar and thus does not concern itself with which URLs and page models use or don't use the editor), I would imagine that we'd have to defer the entire construction of it. Not just the getToolbarButton method call.

At that point, mw.config.get( 'wgPageContentModel' ) !== 'wikitext' ) should become redundant, not even as optimisation, since presumably the majority of cases worth optimising for are already taken care of by virtue of the JS payload itself not being requested on unrelated pages. Plus there is the mw.hook( 'wikiEditor.toolbarReady' ) handler wrapping it all which I would expect not to fire unless WikiEditor is also going to emit addToToolbar, and thus is gurauanteed to be an edit form for a wikitext content model.

Something isn't adding up. I'm not sure what yet :)

Another quick fix might be to defer the new RealtimePreview() ctor to the same callback where getToolbarButton is called if the rest isn't needed outside that context anyway.

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

[mediawiki/extensions/WikiEditor@master] Realtime Preview: only add window-resize handler if toolbar button is used

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

Good point. The constructor shouldn't be adding any event handlers; that should only happen in getToolbarButton(), because that's effectively the entry point for RTP.

I think one issue on test2wiki is that the gadget is being loaded incorrectly. It's got:

* realtimePreview[ResourceLoader|default|dependencies=ext.wikiEditor.realtimepreview]|realtimePreview.js

but should have

* realtimePreview[ResourceLoader|default|dependencies=ext.wikiEditor.realtimepreview|actions=edit]|realtimePreview.js

The bug should of course be fixed in the extension, but avoiding loading the gadget at all for non-edit actions would be good.

handler wrapping it all which I would expect not to fire unless WikiEditor is also going to emit addToToolbar, and thus is gurauanteed to be an edit form for a wikitext content model.

addToToolbar is fired for non-wikitext content models as well, such as JSON, so it does need to check (although we could probably look deeper into that, because I imaging that some non-wikitext pages would benefit from previewing! that's a separate issue though).

Change 811801 merged by jenkins-bot:

[mediawiki/extensions/WikiEditor@master] Realtime Preview: only add window-resize handler if toolbar button is used

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

I tested resizing the browser window while editing. I didn't see any errors in the logs or other misbehaviour (apart from T313210).

RTP can be loaded as either a gadget or an extension, and I tested them both.

Test environments:

Test browser: Firefox 91
Skins:

  • gadget: Vector 2022
  • extension: Vector 2010, Minerva, MonoBook, Timeless