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);
   }

Comments

mamoruua created an issue. See original summary.

mamoruua’s picture

StatusFileSize
new1.24 KB
sourav_paul’s picture

I've tried to recreate the issue by using the following steps but can't replicate it.

I've installed enabled storybook: "1.0.0-beta2" & themed_fast_404: "1.0.6" on d10.3

Please provide proper reproduce steps.

Need More Info...

e0ipso’s picture

Status: Active » Fixed

I made some minor modifications to the patch.

e0ipso’s picture

  • e0ipso committed 25591fb8 on 1.x
    Issue #3472866 by mamoruua, sourav_paul, e0ipso: Error when using Themed...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.