Error when using Themed module fast 404

Created on 8 September 2024, 2 months ago
Updated 9 September 2024, 2 months ago

Problem/Motivation

If the Themed module fast 404 โ†’ module is enabled, it displays an error:

The website encountered an unexpected error. Try again later.

TypeError: Drupal\storybook\Util::isRenderController(): Argument #1 ($request) must be of type Symfony\Component\HttpFoundation\Request, null given, called in /var/www/web/modules/contrib/storybook/src/FileUrlGenerator.php on line 50 in Drupal\storybook\Util::isRenderController() (line 22 of modules/contrib/storybook/src/Util.php).
Drupal\storybook\FileUrlGenerator->generateString('themes/contrib/custom_theme/logo.svg') (Line: 310)
theme_get_setting('features.favicon') (Line: 606)
system_page_attachments(Array) (Line: 311)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'system') (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_attachments', Object) (Line: 308)
Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 285)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 284)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Install and enable the module Themed module fast 404 โ†’
  2. Open any page

Proposed resolution

Get ัurrent Request not at the stage of service initialization in the constructor method, but at the stage of Url string generation, as it is done in the service from the core (Drupal\Core\File\FileUrlGenerator) which is decorated by this module.

diff --git a/storybook/src/FileUrlGenerator.php b/storybook/src/FileUrlGenerator.php
--- a/storybook/src/FileUrlGenerator.php
+++ b/storybook/src/FileUrlGenerator.php	(date 1714061951000)
@@ -22,11 +22,11 @@
   private $fileGenerator;

   /**
-   * The request object.
+   * The request stack.
    *
-   * @var \Symfony\Component\HttpFoundation\Request
+   * @var \Symfony\Component\HttpFoundation\RequestStack
    */
-  private $request;
+  protected $requestStack;

   /**
    * Constructs a file generator decorator.
@@ -38,7 +38,7 @@
    */
   public function __construct(FileUrlGeneratorInterface $fileGenerator, RequestStack $request_stack) {
     $this->fileGenerator = $fileGenerator;
-    $this->request = $request_stack->getCurrentRequest();
+    $this->requestStack = $request_stack;
   }

   /**
@@ -47,7 +47,7 @@
   public function generateString(string $uri): string {
     // This is the only reason to decorate this service. We want all file URLs
     // to be absolute withing the Storybook iframe.
-    return Util::isRenderController($this->request)
+    return Util::isRenderController($this->requestStack->getCurrentRequest())
       ? $this->fileGenerator->generateAbsoluteString($uri)
       : $this->fileGenerator->generateString($uri);
   }
๐Ÿ› Bug report
Status

Fixed

Version

1.0

Component

Storybook

Created by

๐Ÿ‡บ๐Ÿ‡ฆUkraine mamoruua

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024