Page MenuHomePhabricator

Switching from source edit of section to VE causes loss of everything other than that section.
Closed, ResolvedPublicBUG REPORT

Description

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

What happens?:
Just the one section is saved, with the rest deleted. See either of:

What should have happened instead?:
The rest of the article should not have been deleted

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

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

  • MacOS Sonoma
  • Chrome Version 138.0.7204.169 (Official Build) (arm64)

Event Timeline

When you saw this, did it appear to delete the article in the review-changes diff view before saving? Or did it only happen after the save?

Yup, the deletions show in the preview screen:

Screenshot 2025-08-06 at 4.34.20 PM.png (2×2 px, 1 MB)

@Esanders That does include all the converter refactoring, which is at least a bit suspicious.

I can't reproduce this with the 2010 or 2017 wikitext editor (I'm going as far as review changes).

Can anyone provide some reliable reproduction steps, maybe in a sandbox?

@Esanders : I think I might have an idea of why. I tried it right now with either Firefox or Edge, logged in or not, with the same results :

I hope this helps, I can't do better without screenshots.

Hi.
I had the issue before.
I can reproduce the problem on w:fr and w:en on condition that I am logged in.
If I am not logged in, the w:en editor behaves differently, I cannot switch to the editor after editing the wikicode without having to "leave the page" and thus lose the modifications.
Not sure if this is due to my preferences.
Thanks
Lew

matmarex subscribed.

I can reproduce this locally. This bug only happens when switching using the "Edit" / "Edit source" tabs, and not when switching using the dropdown menu in the editor toolbar. (Thanks to @Geertivp for making this clear in T403776, and I see that @Fugace also pointed it out in this task.)

Seems to be caused by https://gerrit.wikimedia.org/r/c/mediawiki/extensions/VisualEditor/+/1168290 changing a !== null to !== undefined.

Ahh, that does explain why I wasn't reproducing it. Further spillover from the switch to default arguments and their null/undefined behavior changes makes sense, I suppose.

Change #1184941 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/VisualEditor@master] DesktopArticleTarget: Fix switching editors with changes while editing a section

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

I took a while writing that single-word patch because I tried to figure out in which places section can be null, undefined, or an empty string, and what exactly does this means in each place. Ultimately I gave up, it's complex and I don't want to spend a lot of time on it only to break some other corner case by accident. The patch fixes this particular scenario for me.

The whole mode switching business is extremely complex, as you can switch: with/without changes, between whole page/section edit/new section, with visual section editing enabled/disabled, from source mode/visual mode/old wikitext editor to source mode/visual mode/old wikitext editor, and I hope I'm not missing any combinations. Some of them are impossible, but it's hard to keep that all in mind. I remember that we broke switching one way or another so many times when I was working on VE more actively in the past.

I think this is one area that would really benefit from browser tests, even though they're unreliable.

Yes - this reminds me of the audit we did for mobile editing, which documents 2^4 = 16 different switching paths

image.png (759×1 px, 82 KB)

tried to figure out in which places section can be null, undefined, or an empty string,

Once processed, section should always be string or null, as documented for example here:

/**
 * Switch to a different wikitext section
 *
 * @param {string|null} section Section to switch to: a number, 'T-'-prefixed number, 'new'
 *   or null (whole document)
 * @param {boolean} [noPrompt=false] Switch without prompting (changes will be lost either way)
 */
ve.init.mw.ArticleTarget.prototype.switchToWikitextSection = function ( section, noPrompt ) {

Change #1184941 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] DesktopArticleTarget: Fix switching editors with changes while editing a section

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

The change will go live on Wikimedia wikis next week, between Tuesday and Thursday, on the usual schedule.