Viewsreference embeds Views without cache, breaking Dynamic page cache

Created on 26 October 2017, about 7 years ago
Updated 29 January 2024, 10 months ago

Problem/Motivation

When a Viewsreference field is rendered, the Dynamic page cache module considers the page uncachable. This reduces scalability considerably.

Proposed resolution

Either implement a lazy builder pattern for embedding views or implement correct cachability metadata on the embedded views, so pages can be cached by Dynamic page cache.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands idebr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ΈSpain javier_rey

    Hi! I think there is a bug in the patch, as it is defined, in line 163, the variable "$render_array" is overwritten, losing the title of the view.

    if ($plugin_types) {
            // Add a custom template if the title is available.
            $title = $view->getTitle();
            if (!empty($title)) {
              // If the title contains tokens, we need to render the view to
              // populate the rowTokens.
              if (strpos($title, '{{') !== FALSE) {
                $view->render();
                $title = $view->getTitle();
              }
              $render_array['title'] = [
                '#theme' => 'viewsreference__view_title',
                '#title' => $title,
              ];
            }
          }
          $render_array = $view->buildRenderable($display_id, $view->args, FALSE);

    Also, when we return an empty array and we have the "Internal Page Cache" module enabled, the page cache is not being refreshed.

    1. Create a view block that lists basic pages with the "tag based" option.
    2. Insert the block as a field inside another type of content, such as a landing page.
    3. Open the landing page as anonymous and as a registered user.
    4. Create a basic page and reload the landing page as anonymous and as a registered user.

    I've added a patch which imo fixes these two cases. I am not an expert, so if there are any problems any help is welcome.

  • Status changed to Fixed over 1 year ago
  • πŸ‡³πŸ‡±Netherlands seanB Netherlands

    Merged the PR with the latest changes from [#26]. Thanks everyone!

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

  • Status changed to Fixed about 1 year ago
  • πŸ‡³πŸ‡±Netherlands wilfred waltman

    This lazy-loading solution messes up one of our javascript because the js runs before the content of the blok is loaded now. I don't know if this solution should be reverted or be made configurable but for know I am going to revert that commit in our project.

    A patch is attached for anyone else experiencing the same issue.

  • πŸ‡ΊπŸ‡¦Ukraine artem_sylchuk Lutsk

    BigPipe triggers Drupal Behaviors after inserting the HTML, you need to properly use behaviors with the proper context variable usage in your JS: https://www.drupal.org/docs/drupal-apis/javascript-api/javascript-api-ov... β†’
    Also there is an issue with bigpipe itself after switching to the MutationObserver API: πŸ› Large placeholders are not processed RTBC

  • πŸ‡ΊπŸ‡ΈUnited States nsciacca

    Thanks @Wilfred Waltman - patch helped me when the View failed to display to logged in users.

  • πŸ‡«πŸ‡·France dark05

    Hello :-) With the version 2.0.0-beta7 any patch works. I'm created my custom patch.

  • πŸ‡ΊπŸ‡ΈUnited States ddavisboxleitner

    On version 8.x-2.0-beta7 of the module, this change is introduced as a separate field formatter:

    https://git.drupalcode.org/project/viewsreference/-/blob/8.x-2.0-beta7/s...

    To enable it (and potentially resolve the issues mentioned in the ticket) you have to select 'Views reference (lazy builder)' as the format for your Views Reference field under Manage Display.

Production build 0.71.5 2024