Last modified: 2013-02-12 19:01:53 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 T24680, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 22680 - Vector EditWarning breaks page caching. Edits get erased when navigating back and forth
Vector EditWarning breaks page caching. Edits get erased when navigating back...
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.17.x
All All
: High major with 3 votes (vote)
: ---
Assigned To: Roan Kattouw
: upstream
Depends on: 25419
Blocks: 44881
  Show dependency treegraph
 
Reported: 2010-02-28 21:44 UTC by Cacycle
Modified: 2013-02-12 19:01 UTC (History)
8 users (show)

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


Attachments
Testcase for cache breaking by onbeforeunload (593 bytes, text/html)
2010-06-07 21:01 UTC, Cacycle
Details
Fixed testcase for cache breaking by onbeforeunload (785 bytes, text/html)
2010-06-07 21:41 UTC, Cacycle
Details

Description Cacycle 2010-02-28 21:44:12 UTC
Navigable TOC / Wiki-Editor break page caching, probably by using an "unload" event, in Firefox (and probably other browsers too).

For details please see https://developer.mozilla.org/En/Using_Firefox_1.5_caching

Essentially, page caching saves javascript states and iframe contents so that accidentally navigating away from a page and coming back does not erase the edits by reloading the page.

Unfortunately, registering an unload event handler breaks this caching. The "pagehide" should be used in browsers that support caching instead of the "unload" event.

If page caching is used when leaving a page can be tested in the "pagehide" event handler with "event.persisted == true".
Comment 1 Trevor Parscal 2010-04-14 12:46:02 UTC
This is actually to do with the Vector/EditWarning extension's use of the onbeforeunload handler.
Comment 2 Trevor Parscal 2010-04-14 12:49:02 UTC
What is the use-case where users loose information by leaving the page and returning without being warned? The Vector/EditWarning extension is designed to provide notice that you will loose changes if you leave.
Comment 3 Cacycle 2010-04-17 15:48:46 UTC
Ironically, it seems to be the message that warns about the caching problems which breaks the page caching ;-)

wikEd users complain that they lose their edit page state upon navigating back and forth (or forth and back), i.e. when you come back, the editor completely reloads from scratch with the original text and all edits are lost. Without cache breaking you simply continue editing where you left the page.

Also, all dynamically loaded images and scripts seem to get lost regularly and will then be reloaded from the server which takes a while.

I think it should be possible to use the pagehide event instead of the onbeforeunload for your purposes if it is available.

And you might not need the message at all if the caching works.
Comment 4 Cacycle 2010-04-17 16:11:57 UTC
For details please see https://developer.mozilla.org/En/Using_Firefox_1.5_caching

Pagehide fires before unload, like the beforeunload event, and allows you to stop the page leave.

In the pagehide handler you can test if the page will not be cached with "event.persisted != true", e.g. to display the warning.
Comment 5 Roan Kattouw 2010-06-07 11:55:35 UTC
(In reply to comment #4)
> For details please see
> https://developer.mozilla.org/En/Using_Firefox_1.5_caching
> 
> Pagehide fires before unload, like the beforeunload event, and allows you to
> stop the page leave.
> 
Actually, no, it doesn't allow you to stop anything. I've tried using event.preventDefault() and return false in a pagehide handler in Firefox 3.6, and they don't have any effect. The HTML 5 spec draft that includes the pagehide event also explicitly says it's uncancelable.

Also, the documentation you link to says hooking the unload event breaks caching, but we only use the *before*unload event, which isn't mentioned. In fact, page caching seems to work fine for me: on a regular edit page, the content of the textarea is restored after clicking OK in the edit warning and going back.

If wikEd has issues with this despite all that, it should probably disable EditWarning. This is not cleanly possible just yet, but will be soon per bug 23807.
Comment 6 Cacycle 2010-06-07 20:28:22 UTC
I just found this tweet https://twitter.com/kangax/status/4057887867: 

`onbeforeunload` invalidates page cache in FF3.5, BUT null'ing `onbeforeunload` in handler itself turns page cache back on. Nice... 9:49 AM Sep 17th, 2009 via Twitterrific kangax
Comment 7 Roan Kattouw 2010-06-07 20:52:00 UTC
(In reply to comment #6)
> I just found this tweet https://twitter.com/kangax/status/4057887867: 
> 
> `onbeforeunload` invalidates page cache in FF3.5, BUT null'ing `onbeforeunload`
> in handler itself turns page cache back on. Nice... 9:49 AM Sep 17th, 2009 via
> Twitterrific kangax
Thank God for Twitter :)

I will implement this tomorrow.
Comment 8 Cacycle 2010-06-07 21:01:19 UTC
Created attachment 7434 [details]
Testcase for cache breaking by onbeforeunload

The tweet was right, removeEventListener in the handler prevents the cache invalidation. Here is simple test case for experimenting.
Comment 9 Cacycle 2010-06-07 21:05:19 UTC
Just be creative in finding a way to reinstate your onbeforeunload handler when you come back to that page :-)
Comment 10 Cacycle 2010-06-07 21:41:18 UTC
Created attachment 7435 [details]
Fixed testcase for cache breaking by onbeforeunload

You can use the pageshow event to reinstate the beforeunload event, see for the working testcase for details.
Comment 11 Roan Kattouw 2010-06-18 18:29:52 UTC
Thank you for digging up this trick. Fixed in r68229.
Comment 12 Cacycle 2010-09-19 17:24:46 UTC
Cache invalidation happens again, leading to lost edits on page navigation and time consuming reloads of images and other elements with every page load. Therefore I have reopened this bug.

This time it happens on en-WP under vector but with all beta features and obviously script-related preference settings including gadgets disabled.
Comment 13 Cacycle 2010-09-19 17:37:30 UTC
Maybe it is this one?

Line 3022 in http://bits.wikimedia.org/w/extensions/UsabilityInitiative/js/plugins.combined.js?283 (code after "// Attach our own handler for onbeforeunload which respects the current one").
Comment 14 Cacycle 2010-09-19 18:40:45 UTC
Also happens under monobook. There seem to be unload events in jquery.js?283s.
Comment 15 Roan Kattouw 2010-09-22 14:57:19 UTC
Happens on all pages, including those that neither Vector nor UsabilityInitiative is on. Could be a bug in jQuery I guess.
Comment 16 Trevor Parscal 2010-09-22 18:38:28 UTC
I recall this had to do with the fact that we were wrapping the textarea, which essentially removes/adds it.
Comment 17 Roan Kattouw 2010-09-23 14:44:02 UTC
(In reply to comment #16)
> I recall this had to do with the fact that we were wrapping the textarea, which
> essentially removes/adds it.

No, that's not the same issue, as this bug occurs with WikiEditor disabled as well.

What's happening is that something, somewhere is either setting an onunload, which will disable bfcache no matter what, or setting an unbeforeunload without cleaning up after themselves properly (which is what EditWarning used to do before I fixed it).
Comment 18 Derk-Jan Hartman 2010-09-24 12:46:52 UTC
jQuery(window).bind('unload',function(){for(var id in jQuery.cache) etc

sounds like a candidate to me.
Comment 19 Cacycle 2010-10-03 12:36:17 UTC
Still happening on Wikipedia. This causes big problem for editors (lost edits) and low-bandwidth users (probably lots of extra traffic).
Comment 20 Roan Kattouw 2010-10-04 20:14:21 UTC
(In reply to comment #18)
> jQuery(window).bind('unload',function(){for(var id in jQuery.cache) etc
> 
> sounds like a candidate to me.
That one did turn out to be one of the culprits, yes. The code inside the unload handler is only needed in IE, and jQuery 1.4 is smart enough to actually only bind the handler in IE. There was a second such occurrence in jquery.stars.js from the ArticleAssessmentPilot extension, which I fixed in r74267.

The fix for jquery.stars went live just now. I will migrate Wikimedia to jQuery 1.4.2 on Monday Oct 11 per bug 25419.
Comment 21 Roan Kattouw 2010-10-11 08:18:15 UTC
Migrating to 1.4.2 seems to have fixed the issue for me (Firefox 3.6.10) in most cases. Going back and forth between normal pages as well as unchanged edit pages uses bfcache just fine.

The only case in which bfcache still breaks (due to a bug in EditWarning that's gonna be hard to fix) is when the edit warning pops up and you click OK. However, bfcache only breaks in the sense that the page is reloaded; the edited text is stil there. This is not totally ideal, but I seriously don't know how we could do better. The bug as filed has been fixed (reloading of pages only occurs in one specific case, and edits don't get erased anymore), so I'm closing this bug.
Comment 22 Cacycle 2011-03-07 07:59:00 UTC
Once again, this problem is back and presents a major problem: the complete edit gets lost when (accidentally) navigating away and back to an edit page.
Comment 23 Roan Kattouw 2011-04-19 15:46:33 UTC
(In reply to comment #22)
> Once again, this problem is back and presents a major problem: the complete
> edit gets lost when (accidentally) navigating away and back to an edit page.

This problem appears on all pages, not just edit pages. It also only appears on enwiki but not on mediawikiwiki or nlwiki, so it's probably a local JS issue. I'll try to see if I can discover what's causing it.
Comment 24 Roan Kattouw 2011-04-19 19:32:55 UTC
I've nailed it down to the WikiMiniAtlas script.

One of the criteria for disabling bfcache that's mentioned in the documentation is "the top-level page contains frames that are not cacheable". WMA inserts an invisible, empty <iframe> on every page view, and I've confirmed that removing the iframe in Firebug fixes the bfcache problem.

I'm not sure how WMA can insert the iframe in a way that won't break bfcache (maybe remove it in an onbeforeunload hook?), but inserting it when needed instead of inserting an empty, invisible one unconditionally on page load would go a long way.

Re-closing as FIXED because this incarnation of the bug is not in MediaWiki, but in WikiMiniAtlas.
Comment 25 Cacycle 2011-04-19 21:40:54 UTC
Please see https://jira.toolserver.org/browse/WMA-32 for the WikiMiniAtlas bug tracker entry.
Comment 26 Cacycle 2011-04-19 21:41:37 UTC
Oh, and thanks for figuring this out!
Comment 27 Cacycle 2012-03-24 22:06:03 UTC
Once again, this problem is back and presents a major problem: the complete
edit gets lost when (accidentally) navigating away and back to an edit page. WMA has been fixed April 2011 as far as I can tell.
Comment 28 Roan Kattouw 2012-03-29 10:49:19 UTC
(In reply to comment #27)
> Once again, this problem is back and presents a major problem: the complete
> edit gets lost when (accidentally) navigating away and back to an edit page.
> WMA has been fixed April 2011 as far as I can tell.
I can't reproduce this in Firefox 11.0. Can you reproduce this when logged out? If not, it's very probably another Gadget or user script causing this.
Comment 29 Cacycle 2012-08-12 10:52:52 UTC
This bug is still there. I can reproduce it with all gadgets disabled and when being logged out (running wikEd from Greasemonkey). It does, however, not happen when using the standard textarea. 

I am wondering if there is a textarea recovering script running in Mediawiki that masks the bug. Any idea?
Comment 30 Cacycle 2012-08-12 15:32:31 UTC
Actually, this seems to be a Firefox bug. I will keep you updated.
Comment 31 Cacycle 2012-08-12 17:25:58 UTC
See here for the Mozilla bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=782132
Comment 32 Bartosz Dziewoński 2013-02-11 22:47:08 UTC
That report was closed as WFM, linking to http://support.ant.com/requests/6520 as the culprit, but that's behind a login-wall for me. What's the status of this?
Comment 33 Cacycle 2013-02-12 19:01:53 UTC
It is a bug in the Firefox addon Ant downloader and they are still working on a fix. Changed Status to Resolved, Worksforme

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


Navigation
Links