Page MenuHomePhabricator

mw.Api#saveOption called twice with different visualeditor-editor values on startup
Closed, ResolvedPublic1 Story Points

Description

On a wiki or with an account where I've not used VisualEditor before (or where preferred editor is set to source editor), switching to VisualEditor results in two api.php requests quickly after one another:

Network activity:

  1. After 1.5s, from setEditorPreference(), from ve.init.mw.DesktopArticleTarget.init's initial $() handler
// ve.init.mw.DesktopArticleTarget.init
$(function () {
	/* .. */
	if ( init.isAvailable ) {
		/* .. */
		if ( init.isVisualAvailable && [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
			/* .. */
			// Remember that the user wanted wikitext, at least this time
			mw.libs.ve.setEditorPreference( 'wikitext' );
POST https://ko.wikipedia.org/w/api.php

action: options
format: json
formatversion: 2
change: visualeditor-editor=wikitext
token: ***
  1. After 3.0s, from requestParsoidData(). GET https://ko.wikipedia.org/w/api.php?action=visualeditor&format=json&paction=metadata
  2. After 3.0s, from requestParsoidData(). POST https://ko.wikipedia.org/api/rest_v1/transform/wikitext/to/html/%EC%82%AC%EC%9A%A9%EC%9E%90%3AKrinkle/0
  3. After 3.1s, from setEditorPreference , from activateTarget(), from OO.ui.mixin.ButtonElement.onClick.
function activateTarget(mode, ) {
           /* .. */
           if (mode === 'visual') {
               setEditorPreference('visualeditor');
POST https://ko.wikipedia.org/w/api.php

action: options
format: json
formatversion: 2
change: visualeditor-editor=visualeditor
token: ***

This consistently happens using the following steps:

  • On Preferences, set edit mode to source editor.
  • Go to a page, edit, and switch to visual editor.
  • Observe two requests to set opposing values.

The first one shouldn't have happened as the preference was already set to wikitext. (Race condition?) And depending on whether it is intentional that the preference is changed (or only when remembering?) The second one either shouldn't happen either, or should happen earlier (in place of the first one).

Event Timeline

Krinkle created this task.Jan 25 2017, 11:23 PM
Restricted Application added a project: VisualEditor. · View Herald TranscriptJan 25 2017, 11:23 PM
Restricted Application added subscribers: revi, Aklapper. · View Herald Transcript
Jdforrester-WMF triaged this task as Normal priority.Feb 6 2017, 7:08 PM
Jdforrester-WMF added a project: Performance.
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.

Change 348020 had a related patch set uploaded (by Jforrester):
[mediawiki/extensions/VisualEditor@master] DesktopArticleTarget.init: Don't call setEditorPreference twice

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

Change 348020 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] DesktopArticleTarget.init: Don't call setEditorPreference twice

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

Jdforrester-WMF closed this task as Resolved.Apr 19 2017, 6:38 PM
Jdforrester-WMF removed a project: Patch-For-Review.

Believed resolved.

Restricted Application added a project: User-Ryasmeen. · View Herald TranscriptApr 19 2017, 6:38 PM