 core/modules/contact/contact.module                | 10 ++-
 core/modules/help/src/Tests/HelpEmptyPageTest.php  | 65 +++++++++++++++++++
 .../tests/modules/help_test/help_test.info.yml     |  5 ++
 .../modules/help_test/src/SuperNovaGenerator.php   | 74 ++++++++++++++++++++++
 core/modules/user/user.module                      |  9 +--
 .../views/src/Plugin/views/display/Page.php        |  3 +-
 6 files changed, 157 insertions(+), 9 deletions(-)

diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module
index b0b6838..3354ca3 100644
--- a/core/modules/contact/contact.module
+++ b/core/modules/contact/contact.module
@@ -13,12 +13,14 @@
  * Implements hook_help().
  */
 function contact_help($route_name, RouteMatchInterface $route_match) {
-  $menu_page = \Drupal::moduleHandler()->moduleExists('menu_ui') ? \Drupal::url('entity.menu.collection') : '#';
-  $block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
-  $contact_page = \Drupal::url('entity.contact_form.collection');
+  // Only generate necessary URLs inside the switch cases, to ensure no work is
+  // done at all when no help is displayed.
 
   switch ($route_name) {
     case 'help.page.contact':
+      $menu_page = \Drupal::moduleHandler()->moduleExists('menu_ui') ? \Drupal::url('entity.menu.collection') : '#';
+      $block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
+      $contact_page = \Drupal::url('entity.contact_form.collection');
       $output = '';
       $output .= '<h3>' . t('About') . '</h3>';
       $output .= '<p>' . t('The Contact module allows visitors to contact registered users on your site, using the personal contact form, and also allows you to set up site-wide contact forms. For more information, see the <a href="!contact">online documentation for the Contact module</a>.', array('!contact' => 'https://www.drupal.org/documentation/modules/contact')) . '</p>';
@@ -36,6 +38,8 @@ function contact_help($route_name, RouteMatchInterface $route_match) {
       return $output;
 
     case 'entity.contact_form.collection':
+      $menu_page = \Drupal::moduleHandler()->moduleExists('menu_ui') ? \Drupal::url('entity.menu.collection') : '#';
+      $block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
       $output = '';
       $output .= '<p>' . t('The <em>Personal contact form</em> is the form for site visitors to contact registered users; the name and recipients of this form cannot be edited. Other forms listed here are your configured site-wide contact forms, which site visitors can use to send mail to a centralized email address or addresses. You can edit the name and recipients of site-wide forms by choosing the <em>Edit</em> operation. You can also configure the fields and display of both personal and site-wide forms.') . '</p>';
       $output .= '<p>' . t('If you have configured a default site-wide contact form, a <em>Contact</em> menu link in the <em>Footer</em> menu will link to it. You can modify this link from the <a href="!menu-settings">Menus page</a> if you have the Menu UI module installed. You can also create links to other contact forms; the URL has format contact/machine_name_of_form.', array('!menu-settings' => $menu_page)) . '</p>';
diff --git a/core/modules/help/src/Tests/HelpEmptyPageTest.php b/core/modules/help/src/Tests/HelpEmptyPageTest.php
new file mode 100644
index 0000000..6a4404e
--- /dev/null
+++ b/core/modules/help/src/Tests/HelpEmptyPageTest.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\help\Tests\HelpEmptyPageTest.
+ */
+
+namespace Drupal\help\Tests;
+
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Routing\RouteMatch;
+use Drupal\help_test\SuperNovaGenerator;
+use Drupal\simpletest\KernelTestBase;
+
+/**
+ * Tests the empty HTML page.
+ *
+ * @group help
+ */
+class HelpEmptyPageTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['system', 'help_test', 'user'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->installSchema('system', 'router');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function containerBuild(ContainerBuilder $container) {
+    parent::containerBuild($container);
+
+    $container->set('url_generator', new SupernovaGenerator());
+  }
+
+  /**
+   * Ensures that no URL generator is called on a page without hook_help().
+   */
+  public function testEmptyHookHelp() {
+    $all_modules = system_rebuild_module_data();
+    $all_modules = array_filter($all_modules, function ($module) {
+      // Filter contrib, hidden, already enabled modules and modules in the
+      // Testing package.
+      if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') {
+        return FALSE;
+      }
+      return TRUE;
+    });
+
+    \Drupal::service('module_installer')->install(array_keys($all_modules));
+
+    $route = \Drupal::service('router.route_provider')->getRouteByName('<front>');
+    \Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
+  }
+
+}
diff --git a/core/modules/help/tests/modules/help_test/help_test.info.yml b/core/modules/help/tests/modules/help_test/help_test.info.yml
new file mode 100644
index 0000000..897ea6e
--- /dev/null
+++ b/core/modules/help/tests/modules/help_test/help_test.info.yml
@@ -0,0 +1,5 @@
+name: help_test
+type: module
+core: 8.x
+dependencies:
+  - help
diff --git a/core/modules/help/tests/modules/help_test/src/SuperNovaGenerator.php b/core/modules/help/tests/modules/help_test/src/SuperNovaGenerator.php
new file mode 100644
index 0000000..9b33f94
--- /dev/null
+++ b/core/modules/help/tests/modules/help_test/src/SuperNovaGenerator.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\help_test\SuperNovaGenerator.
+ */
+
+namespace Drupal\help_test;
+
+use Drupal\Core\Routing\UrlGeneratorInterface;
+use Symfony\Component\Routing\RequestContext;
+
+/**
+ * Implements a URL generator which always thrown an exception.
+ */
+class SuperNovaGenerator implements UrlGeneratorInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setContext(RequestContext $context) {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getContext() {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function generateFromPath($path = NULL, $options = array()) {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getPathFromRoute($name, $parameters = array()) {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function generateFromRoute($name, $parameters = array(), $options = array()) {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function supports($name) {
+    throw new \Exception();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRouteDebugMessage($name, array $parameters = array()) {
+    throw new \Exception();
+  }
+
+}
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 3ca4698..33ed45f 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1136,11 +1136,12 @@ function user_role_change_permissions($rid, array $permissions = array()) {
  */
 function user_role_grant_permissions($rid, array $permissions = array()) {
   // Grant new permissions for the role.
-  $role = Role::load($rid);
-  foreach ($permissions as $permission) {
-    $role->grantPermission($permission);
+  if ($role = Role::load($rid)) {
+    foreach ($permissions as $permission) {
+      $role->grantPermission($permission);
+    }
+    $role->save();
   }
-  $role->save();
 }
 
 /**
diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php
index 27905b8..751b2fe 100644
--- a/core/modules/views/src/Plugin/views/display/Page.php
+++ b/core/modules/views/src/Plugin/views/display/Page.php
@@ -479,8 +479,7 @@ public function calculateDependencies() {
     $dependencies = parent::calculateDependencies();
 
     $menu = $this->getOption('menu');
-    if ($menu['type'] === 'normal') {
-      $menu_entity = $this->menuStorage->load($menu['menu_name']);
+    if ($menu['type'] === 'normal' && ($menu_entity = $this->menuStorage->load($menu['menu_name']))) {
       $dependencies[$menu_entity->getConfigDependencyKey()][] = $menu_entity->getConfigDependencyName();
     }
 
