diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module
index 3e6f989c34752a81b5bcf45cb41cbc5ad29a4a4e..05c6fb8febffc33ff29af587c94d80fceac49ed4 100644
--- a/core/modules/overlay/overlay.module
+++ b/core/modules/overlay/overlay.module
@@ -462,7 +462,10 @@ function overlay_get_mode() {
  */
 function overlay_set_mode($mode = NULL) {
   global $base_path;
-  $overlay_mode = &drupal_static(__FUNCTION__);
+  // We're not using drupal_static() here since the static cache is reset in
+  // drupal_flush_all_caches(); this could lead to the loss of the overlay when
+  // submitting the admin/modules form, for instance.
+  static $overlay_mode;
 
   // Make sure external resources are not included more than once. Also return
   // the current mode, if no mode was specified.