From: Ori Livneh Date: Tue, 12 Nov 2013 19:19:57 +0000 (-0800) Subject: Rather than upsert module store, explicitly remove old value and then add new one X-Git-Tag: 1.31.0-rc.0~18053^2~1 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=fbf0c812711a22bfbddf52ee69f052cd46d515f8;p=lhc%2Fweb%2Fwiklou.git Rather than upsert module store, explicitly remove old value and then add new one Replacing the content of the module store might fail if the new contents would exceed the browser's localStorage size limit. To avoid clogging the browser with stale data, always remove the old value before attempting to set the new one. Change-Id: I91d01d845a1a633414b94cc02e142a9956955c9d --- diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 1f89792b2f..328ba836c5 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -1944,14 +1944,19 @@ var mw = ( function ( $, undefined ) { var timer; function flush() { - var data; + var data, key = mw.loader.store.getStoreKey(); if ( mw.loader.store.enabled !== true ) { return false; } mw.loader.store.prune(); try { + // Replacing the content of the module store might fail if the new + // contents would exceed the browser's localStorage size limit. To + // avoid clogging the browser with stale data, always remove the old + // value before attempting to set the new one. + localStorage.removeItem( key ); data = JSON.stringify( mw.loader.store ); - localStorage.setItem( mw.loader.store.getStoreKey(), data ); + localStorage.setItem( key, data ); } catch (e) {} }