Hello there
When using .addClass() twig method within template and enabled big_pipe it won't work for anonymous users. Admin user works fine.

/**
 * @file
 * Sidebar navigation template.
 *
 * Available variables:
 * - attributes: Attributes.
 * - title_suffix: Title suffix. To place contextual links.
 * - content: Block content.
 *
 * @ingroup themeable
 */
{% set panel_classes = ['panel', 'panel-default', 'panel-subnav'] %}
<div{{ attributes.addClass(panel_classes) }}>
  {{ title_suffix }}
  {{ content }}
</div>

Resulting into

<div>
  ...
  ...
</div>

Theme definition

/**
 * Implements hook_theme().
 */
function example_menu_theme($existing, $type, $theme, $path) {
  return [
    'sidebar_navigation' => [
      'variables' => [
        'content' => NULL,
        'attributes' => NULL,
      ],
      'template' => 'sidebar-navigation',
    ],
  ];
}

Template call

/**
 * Implements hook_preprocess_node().
 */
function example_preprocess_node(&$variables) {
      $menu_name = 'example';
      $variables['sidebar_navigation'] = [
        '#theme' => 'sidebar_navigation',
        '#content' => [
          '#contextual_links' => [
            'menu' => [
              'route_parameters' => ['menu' => $menu_name],
            ],
          ],
        ],
      ];
}

Comments

podarok created an issue. See original summary.

podarok’s picture

Issue summary: View changes
krlucas’s picture

@podarok I am unable to reproduce on a standard Drupal 8 install.

Many core templates use attributes.addClass. They all seem to be rendering the classes specified when Big Pipe is enabled and pages are viewed as an anonymous user.

Can you provide some more detailed testing instructions? I notice your code snippet references Panels...

krlucas’s picture

Priority: Major » Normal
podarok’s picture

Issue summary: View changes
podarok’s picture

Hey
I've put some additional info about using template into issue's summary

Fix was done by putting attributes into hook_preprocess_node

/**
 * Implements hook_preprocess_node().
 */
function ymca_menu_preprocess_node(&$variables) {
      $menu_name = 'example';
      // We need custom template here to implement custom contextual links.
      $variables['sidebar_navigation'] = [
        '#theme' => 'sidebar_navigation',
        '#content' => [
          '#contextual_links' => [
            'menu' => [
              'route_parameters' => ['menu' => $menu_name],
            ],
          ],
        ],
        '#attributes' => ['class' => ['panel', 'panel-default', 'panel-subnav']]
      ];
}

and for template

{#
/**
 * @file
 * Sidebar navigation template.
 *
 * Available variables:
 * - attributes: Attributes.
 * - title_suffix: Title suffix. To place contextual links.
 * - content: Block content.
 *
 * @ingroup themeable
 */
#}
<div{{ attributes }}>
  {{ title_suffix }}
  {{ content }}
</div>
podarok’s picture

I notice your code snippet references Panels...

No, we aren't using panels, these classes are for theming only

krlucas’s picture

Status: Active » Closed (won't fix)

This has nothing to do with Big Pipe. You declared a brand new theme hook and template but never initialized the attributes variable in a preprocessor before trying to use it in the template.

$variables['attributes'] = new Attribute();

No idea why you were seeing different results for anonymous/admin.

Feel free to re-open with a patch on a clean Drupal 8 install that clearly demonstrates the bug.