Skip to content
Snippets Groups Projects
Commit d6d5051f authored by catch's avatar catch
Browse files

Issue #3303874 by alecsmrekar, Wim Leers, smustgrave: Early rendering issue in...

Issue #3303874 by alecsmrekar, Wim Leers, smustgrave: Early rendering issue in big_pipe_page_attachments() for controllers returning Response objects
parent 4421948a
Branches
Tags
27 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -281,7 +281,9 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte
}
// Allow hooks to add attachments to $page['#attached'].
$this->invokePageAttachmentHooks($page);
$this->renderer->executeInRenderContext(new RenderContext(), function () use (&$page) {
$this->invokePageAttachmentHooks($page);
});
return [$page, $title];
}
......
......@@ -210,6 +210,12 @@ function common_test_page_attachments(array &$page) {
'#markup' => 'test',
];
}
if (\Drupal::state()->get('common_test.hook_page_attachments.early_rendering', FALSE)) {
// Do some early rendering.
$element = ['#markup' => '123'];
\Drupal::service('renderer')->render($element);
}
}
/**
......
......@@ -20,3 +20,11 @@ common_test.js_and_css_querystring:
_controller: '\Drupal\common_test\Controller\CommonTestController::jsAndCssQuerystring'
requirements:
_access: 'TRUE'
common_test.page_attachments:
path: '/common/attachments-test'
defaults:
_title: 'Attachments test'
_controller: '\Drupal\common_test\Controller\CommonTestController::attachments'
requirements:
_access: 'TRUE'
......@@ -92,4 +92,20 @@ public function destination() {
return new Response($output);
}
/**
* Returns a sample response with some early rendering in
* common_test_page_attachments.
*
* @return \Symfony\Component\HttpFoundation\Response
* A new Response object.
*/
public function attachments() {
\Drupal::state()->set('common_test.hook_page_attachments.early_rendering', TRUE);
$build = [
'#title' => 'A title',
'content' => ['#markup' => 'Some content'],
];
return \Drupal::service('main_content_renderer.html')->renderResponse($build, \Drupal::requestStack()->getCurrentRequest(), \Drupal::routeMatch());
}
}
......@@ -3,6 +3,8 @@
namespace Drupal\Tests\system\Kernel\Common;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Test page rendering hooks.
......@@ -77,4 +79,18 @@ public function assertPageRenderHookExceptions(string $module, string $hook): vo
\Drupal::state()->set($module . '.' . $hook . '.render_array', FALSE);
}
/**
* Assert that HtmlRenderer::invokePageAttachmentHooks is called in a render
* context.
*/
public function testHtmlRendererAttachmentsRenderContext(): void {
$this->enableModules(['common_test', 'system']);
\Drupal::state()->set('common_test.hook_page_attachments.render_url', TRUE);
$uri = '/common/attachments-test';
$request = new Request([], [], [], [], [], ['REQUEST_URI' => $uri, 'SCRIPT_NAME' => $uri]);
$response = \Drupal::service('http_kernel')->handle($request);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment