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.

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

nikita_tt created an issue. See original summary.

nikita_tt’s picture

Status: Active » Needs review
antonio.cangemi’s picture

Assigned: Unassigned » antonio.cangemi
Status: Needs review » Patch (to be ported)

// 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'];

drdam made their first commit to this issue’s fork.

drdam’s picture

Status: Patch (to be ported) » Fixed

Fixed in 1.0.4

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

drdam’s picture

Status: Fixed » Closed (fixed)