AlterBodySubscriber error when response HTML does not contain ___storybook_wrapper

Created on 12 February 2024, 4 months ago
Updated 13 March 2024, 3 months ago

Problem/Motivation

We have a custom module that calls ContainerAwareEventDispatcher::dispatchRequest() to dispatch a fake request.
This request is caught by AlterBodySubscriber::alter() which fails with this error:

DOMNode::appendChild(): Argument #1 ($node) must be of type DOMNode, null given

Steps to reproduce

    $fakeResponse = new HtmlResponse();
    $fakeResponse->setContent($html);

    $event = new ResponseEvent(
      \Drupal::service('http_kernel'),
      \Drupal::requestStack()->getMainRequest()->duplicate(),
      HttpKernelInterface::SUB_REQUEST,
      $fakeResponse
    );
    $this->eventDispatcher->dispatch($event, KernelEvents::RESPONSE);

Proposed resolution

AlterBodySubscriber should make sure ___storybook_wrapper exists before trying to use it.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Other tooling

Created by

πŸ‡«πŸ‡·France prudloff Lille

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024