Problem/Motivation
The website encountered an unexpected error. Try again later.
AssertionError: #lazy_builder callbacks must return a valid renderable array, got NULL from Drupal\views_block_with_lazy_builder\Plugin\Block\ViewsBlockWithLazyBuilder::viewsBlockWithLazyBuilderCallback in assert() (line 403 of core/lib/Drupal/Core/Render/Renderer.php).
assert(, '#lazy_builder callbacks must return a valid renderable array, got NULL from Drupal\views_block_with_lazy_builder\Plugin\Block\ViewsBlockWithLazyBuilder::viewsBlockWithLazyBuilderCallback') (Line: 403)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 165)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 166)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 183)
Drupal\Core\Render\Renderer->doRenderPlaceholder(Array) (Line: 220)
Drupal\Core\Render\Renderer->renderPlaceholder('callback=Drupal%5Cviews_block_with_lazy_builder%5CPlugin%5CBlock%5CViewsBlockWithLazyBuilder%3A%3AviewsBlockWithLazyBuilderCallback&args%5Bsettings%5D=%7B%22id%22%3A%22views_bloc_with_lazy_builder_example%3Awpss_cp_products-recommended_products_block%22%2C%22label%22%3A%22%22%2C%22label_display%22%3A%22visible%22%2C%22provider%22%3A%22views_block_with_lazy_builder%22%2C%22views_label%22%3A%22%22%2C%22items_per_page%22%3A%22none%22%2C%22context_mapping%22%3A%5B%5D%7D&token=bV68bSVsi-ljbCZHUZbpM7exxEXMzAOoRowAvEGuiac', Array) (Line: 723)
Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=Drupal%5Cviews_block_with_lazy_builder%5CPlugin%5CBlock%5CViewsBlockWithLazyBuilder%3A%3AviewsBlockWithLazyBuilderCallback&args%5Bsettings%5D=%7B%22id%22%3A%22views_bloc_with_lazy_builder_example%3Awpss_cp_products-recommended_products_block%22%2C%22label%22%3A%22%22%2C%22label_display%22%3A%22visible%22%2C%22provider%22%3A%22views_block_with_lazy_builder%22%2C%22views_label%22%3A%22%22%2C%22items_per_page%22%3A%22none%22%2C%22context_mapping%22%3A%5B%5D%7D&token=bV68bSVsi-ljbCZHUZbpM7exxEXMzAOoRowAvEGuiac', Array) (Line: 554)
Drupal\big_pipe\Render\BigPipe->Drupal\big_pipe\Render\{closure}()
Fiber->start() (Line: 566)
Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object) (Line: 305)
Drupal\big_pipe\Render\BigPipe->sendContent(Object) (Line: 112)
Drupal\big_pipe\Render\BigPipeResponse->sendContent() (Line: 423)
Symfony\Component\HttpFoundation\Response->send() (Line: 20)
Steps to reproduce
When the views block doesn't have any results and doesn't have "no results behaviour" then it leads to the assertion error.
Proposed resolution
The lazy builder callback should return a valid renderable array always. So I think there is no need to use part of the rendered views block. The whole renderable array can be returned instead of only "view_build" element.
Comments
Comment #3
nikita_ttComment #4
antonio.cangemi commented// Use parent Build to render block as native.
$render = $plugin_block->parentBuild();
// Ensure $render is a valid array and contains the 'view_build' key.
// If the view is empty or contextual filters are invalid, 'view_build'
// may be missing, which would trigger a TypeError in the Renderer.
if (!isset($render['view_build']) || !is_array($render)) {
return [];
}
// Add the cache tags/contexts.
\Drupal::service('renderer')->addCacheableDependency($render, $plugin_block);
// Return view build.
return $render['view_build'];
Comment #6
drdam commentedFixed in 1.0.4
Comment #8
drdam commented