Last modified: 2012-11-28 22:47:05 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T35566, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 33566 - EditWarning should use $.fn.bind instead of window.onbeforeunload directly
EditWarning should use $.fn.bind instead of window.onbeforeunload directly
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
WikiEditor (Other open bugs)
unspecified
All All
: High normal (vote)
: MW 1.20 version
Assigned To: Roan Kattouw
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-01-06 18:10 UTC by Dan Barrett
Modified: 2012-11-28 22:47 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Untested patch (3.04 KB, patch)
2012-02-02 11:11 UTC, Roan Kattouw
Details

Description Dan Barrett 2012-01-06 18:10:08 UTC
This is a followup to bug 33497.

On further consultation with some JavaScript developers, WikiEditor seems to be doing its beforeunload handler incorrectly, or at least not optimally.  The style of:

window.onbeforeunload = function() {
  return something();
};

assumes there is only one such handler on beforeunload, and will clash with other beforeunload handlers in extensions, such as this style:

$(window)
    .bind('beforeunload', myFunc);

WikiEditor's logic should be rewritten to play nicely with other handlers.
Comment 1 Dan Barrett 2012-01-06 18:10:46 UTC
This is in IE8.
Comment 2 Krinkle 2012-01-14 04:19:11 UTC
Agreed that this logic is in jQuery and we should use it. However I don't think it's causing any problems right now. Let's look at the snippet in question:


		context.fallbackWindowOnBeforeUnload = window.onbeforeunload;
		window.onbeforeunload = function() {
			context.$textarea.val( context.$textarea.textSelection( 'getContents' ) );
			if ( context.fallbackWindowOnBeforeUnload ) {
				return context.fallbackWindowOnBeforeUnload();
			}
		};

It preserves the previous value, including support for multiple levels. If this is broken, it's not because of WikiEditor, since it doesn't overwrite itself. If this handler isn't called, it's because another script removes it, not the other way around.

Ironically, it's actually $(window).bind that overwrites any pre-existing on-* handler. The normal event queue doesn't work cross-browser (in that jQuery can't use window.addEventListener internally) so it keeps its own load queue and in that jQuery boldly overwrites any existing handler.

Solution is the same though, as long as everything uses jQuery the queue will stay in tact.
Comment 3 Roan Kattouw 2012-02-02 11:10:59 UTC
The offending code is actually in extensions/Vector/modules/ext.vector.editWarning.js . There is one occurrence in WikiEditor, but it's in a deprecated module.

The code in EditWarning has been very carefully calibrated not to break the back/forward cache in Firefox, so I don't want to touch it right before a release. I'll submit a patch here that you can try out, and if it doesn't break Firefox's bfcache, we can put it in 1.20.
Comment 4 Roan Kattouw 2012-02-02 11:11:43 UTC
Created attachment 9948 [details]
Untested patch
Comment 5 Mark A. Hershberger 2012-02-11 18:39:49 UTC
(In reply to comment #4)
> Created attachment 9948 [details]
> Untested patch

Is there any reason to keep this out of 1.19?
Comment 6 Andre Klapper 2012-05-08 09:13:40 UTC
Can somebody please review the patch and afterwards replace the "patch-need-review" keyword by "patch-reviewed"?
Comment 7 Krinkle 2012-08-24 17:57:56 UTC
@Roan: Please push to gerrit for review. That'll make it easier to test and build upon.
Comment 8 Roan Kattouw 2012-09-05 18:47:16 UTC
(In reply to comment #7)
> @Roan: Please push to gerrit for review. That'll make it easier to test and
> build upon.
Rewrote the patch against current master and submitted as https://gerrit.wikimedia.org/r/#/c/22745/
Comment 9 db [inactive,noenotif] 2012-11-28 14:17:46 UTC
(In reply to comment #8)
> https://gerrit.wikimedia.org/r/#/c/22745/

Status Merged

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links