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
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
Comment #3
prudloff commentedComment #4
e0ipsoI am a bit puzzled by this. This code should only execute when sending a response from the
storybook.render_storycontroller. Which in this case is guaranteed to pass thoseifstatements, right?In any case, I am all in for defensive coding. So I will merge this one.
Comment #6
e0ipsoComment #7
prudloff commentedWhat 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.)
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!