Support '&editintro=…' etc. on subsequent loads via page tabs

Before this change DesktopArticleTarget's history management was not
working correctly because .currentUrl was not being updated on every
activation, and we worked around this problem by activating it in a
different way on subsequent loads in DesktopArticleTarget.init.

Fix the first bug by updating .currentUrl whenever we activate it,
and remove the guards around the normal way of activating it, which
fixes the parsing of 'editintro' parameter.

Bug: T56029
Change-Id: Ifd6af60cdf1d2c87536017b316ab8da1f5133400
This commit is contained in:
Bartosz Dziewoński 2023-06-20 09:13:57 +02:00 committed by Bartosz Dziewoński
parent bcabb774ab
commit eedafae69e
2 changed files with 18 additions and 21 deletions

View file

@ -1094,8 +1094,8 @@ ve.init.mw.DesktopArticleTarget.prototype.updateHistoryState = function () {
var veaction = this.getDefaultMode() === 'visual' ? 'edit' : 'editsource',
section = this.section;
// Push veaction=edit(source) url in history (if not already. If we got here by a veaction=edit(source)
// permalink then it will be there already and the constructor called #activate)
// Push veaction=edit(source) url in history (if not already present).
// If we got here from DesktopArticleTarget.init, then it will be already present.
if (
!this.actFromPopState &&
(

View file

@ -600,6 +600,7 @@
var deactivating = target.deactivatingDeferred || $.Deferred().resolve();
return deactivating.then( function () {
target.currentUrl = new URL( location.href );
var activatePromise = target.activate( dataPromise );
// toolbarSetupDeferred resolves slightly before activatePromise, use done
@ -638,7 +639,6 @@
trackActivateStart( { type: 'page', mechanism: mw.config.get( 'wgArticleId' ) ? 'click' : 'new', mode: mode }, linkUrl );
if ( !active ) {
if ( url.searchParams.get( 'action' ) !== 'edit' && !( url.searchParams.get( 'veaction' ) in veactionToMode ) ) {
// Replace the current state with one that is tagged as ours, to prevent the
// back button from breaking when used to exit VE. FIXME: there should be a better
// way to do this. See also similar code in the DesktopArticleTarget constructor.
@ -648,7 +648,6 @@
history.pushState( { tag: 'visualeditor' }, '', linkUrl || ( mode === 'source' ? veEditSourceUrl : veEditUrl ) );
// Update URL instance
url = linkUrl || veEditUrl;
}
activateTarget( mode, section, undefined, modified );
}
@ -1262,14 +1261,12 @@
trackActivateStart( { type: 'section', mechanism: section === 'new' ? 'new' : 'click', mode: mode }, linkUrl );
if ( !active ) {
if ( url.searchParams.get( 'action' ) !== 'edit' && !( url.searchParams.get( 'veaction' ) in veactionToMode ) ) {
// Replace the current state with one that is tagged as ours, to prevent the
// back button from breaking when used to exit VE. FIXME: there should be a better
// way to do this. See also similar code in the DesktopArticleTarget constructor.
history.replaceState( { tag: 'visualeditor' }, '', url );
// Use linkUrl to preserve the 'section' parameter and others like 'editintro' (T56029)
history.pushState( { tag: 'visualeditor' }, '', linkUrl );
}
// Update URL instance
url = linkUrl;