Page MenuHomePhabricator

"Uncaught TypeError: Cannot read property '0' of undefined" and VE not loading when repeatedly switching back and forth between read and edit modes
Closed, ResolvedPublic8 Estimated Story Points

Description

On any Wikipedia (including SET when "show both editor tabs" is the chosen editing preference), any browser AFAICT (I'm reproducing in Win8):

  1. hit the "Edit" link for a section;
  2. VE loads correctly. Now hit the Back button in the browser;
  3. hit that "Edit" link again;
  4. observe that VE doesn't load (progress bar is complete, but nothing happens).

Console says "Uncaught TypeError: Cannot read property '0' of undefined".
Reported by editors at ja.wiki.

Event Timeline

I tried to reproduce this, but the above mentioned steps are not producing the bug. But I have found another set of steps to reproduce the same error:

  1. Make sure in your Preferences section you have "Show me both editor tabs" set.
  2. Now go to Read mode
  3. Click on Edit tab
  4. Go back to Read mode
  5. Now click on the Section Edit link not the Edit tab

Observed Result:
Progress bar stops before it completes, VE does not load. Error in the console:
Uncaught TypeError: Cannot read property '0' of undefined

Screen Shot 2016-05-17 at 8.29.24 PM.png (747×1 px, 226 KB)

Jdforrester-WMF renamed this task from "Uncaught TypeError: Cannot read property '0' of undefined" and VE not loading to "Uncaught TypeError: Cannot read property '0' of undefined" and VE not loading when repeatedly switching back and forth between read and edit modes.May 31 2016, 7:10 PM
Jdforrester-WMF set the point value for this task to 8.
Jdforrester-WMF moved this task from To Triage to TR0: Interrupt on the VisualEditor board.
AlexMonk-WMF subscribed.

The original steps worked for me. It seems that we actually start the target loading process twice (causing the loading progress counter to be incremented too much and go into undefined indexes of progressSteps), because onEditSectionLinkClick gets called multiple times - so something is setting that function up as handler again when we close VE (or when we reopen it).

Looks like it may be this, in DAT.init.js:

deactivate: function () {
	if (
		userPrefPreferShow &&
		( !conf.singleEditTab || tabPreference === 'multi-tab' )
	) {
		init.setupSectionLinks();
	}
}

This setupSectionLinks call used to run on *save* because we replace the page contents, and therefore click handlers need to be set up again. https://gerrit.wikimedia.org/r/#/c/283591/ changed it to run on any deactivation like this. Of course, in this case, the code is getting run without any save and therefore we don't need to set up the click handlers again.

Change 296496 had a related patch set uploaded (by Alex Monk):
Replace section edit click handlers in DAT instead of doing it badly in init

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

Change 296496 merged by jenkins-bot:
Replace section edit click handlers in DAT instead of doing it badly in init

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