Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.412
diff -u -p -r1.412 menu.inc
--- includes/menu.inc	27 Sep 2010 22:11:38 -0000	1.412
+++ includes/menu.inc	2 Oct 2010 22:43:16 -0000
@@ -1618,20 +1618,29 @@ function menu_get_active_help() {
  */
 function menu_get_custom_theme($initialize = FALSE) {
   $custom_theme = &drupal_static(__FUNCTION__);
+
   // Skip this if the site is offline or being installed or updated, since the
   // menu system may not be correctly initialized then.
   if ($initialize && !_menu_site_is_offline(TRUE) && (!defined('MAINTENANCE_MODE') || (MAINTENANCE_MODE != 'update' && MAINTENANCE_MODE != 'install'))) {
-    // First allow modules to dynamically set a custom theme for the current
-    // page. Since we can only have one, the last module to return a valid
-    // theme takes precedence.
+    // First, initialize the menu router item for the current page. We do this
+    // even when it is not being used below, because initializing the router
+    // item triggers access callback and loader functions for the current page
+    // to be called, and we want those to be consistently triggered at the same
+    // point in the bootstrap.
+    $router_item = menu_get_item();
+
+    // Allow modules to dynamically set a custom theme for the current page.
+    // Since we can only have one, the last module to return a valid theme
+    // takes precedence.
     $custom_themes = array_filter(module_invoke_all('custom_theme'), 'drupal_theme_access');
     if (!empty($custom_themes)) {
       $custom_theme = array_pop($custom_themes);
     }
-    // Otherwise, execute the theme callback function for the current page, if
-    // there is one, in order to determine the custom theme to set.
+
+    // If no module set a valid custom theme, execute the theme callback
+    // function for the current page, if there is one, in order to determine
+    // the custom theme to set.
     if (!isset($custom_theme)) {
-      $router_item = menu_get_item();
       if (!empty($router_item['access']) && !empty($router_item['theme_callback']) && function_exists($router_item['theme_callback'])) {
         $theme_name = call_user_func_array($router_item['theme_callback'], $router_item['theme_arguments']);
         if (drupal_theme_access($theme_name)) {
@@ -1640,6 +1649,7 @@ function menu_get_custom_theme($initiali
       }
     }
   }
+
   return $custom_theme;
 }
 
