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.

Issue fork storybook-3420900

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
e0ipso’s picture

Status: Needs review » Fixed

I am a bit puzzled by this. This code should only execute when sending a response from the storybook.render_story controller. Which in this case is guaranteed to pass those if statements, right?

In any case, I am all in for defensive coding. So I will merge this one.

  • e0ipso committed 166c34db on 1.x authored by prudloff
    Issue #3420900 by prudloff: AlterBodySubscriber error when response HTML...
e0ipso’s picture

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support to this project makes my volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work I did in this project, those include:
  • Triaging issues, and adding more context to existing issues.
  • Writing documentation, or patches for this project.
  • Writing blog posts, speaking about it at conferences.
prudloff’s picture

I am a bit puzzled by this. This code should only execute when sending a response from the storybook.render_story controller.

What we do is clearly atypical and an edge-case.
(Basically we trigger a response event on a fake request in order to trigger response event subscribres on HTML that is rendered separately from the main response, kind of like what big_pipe does.)

In any case, I am all in for defensive coding. So I will merge this one.

I normally would have fixed this on our side, but it seemed like a good occasion to make the storybook code more robust; I am glad we agree on this, thanks!

Status: Fixed » Closed (fixed)

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