Attaching libraries in modules I'm trying to attach a library in a custom shortcode but it doesn't show up neither using render array nor using attach_library twig function.

  class MyTimeline extends ShortcodeBase {
  public function process($attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
    $output = [
      '#theme' =&gt; 'my_timeline_theme',
      '#attached' =&gt; array(
        'library' =&gt; array('my_timeline/timeline')
      ),
    ];
    return $this-&gt;render($output);
  }


mymodule/my_timeline_theme.html.twig

{{ attach_library('my_timeline/timeline') }}


The only way I can attach it is using this last line in the active theme,
ie node.html.twig
The ShortcodeBase Class uses renderplain which strips 'the attached assets and cache tags'

In the comments to the source code they say: We use renderplain so that the shortcode's cache tags would not bubble up to the parent and affect cacheability. Shortcode should be part of contentand self-container.

In order to attach the library I then rendered the Array with this code: 

$renderer = \Drupal::service('renderer');
return $renderer-&gt;render($output);


and it works. Need to understand if and how it affects cache, though.