Unverified Commit 66b2bf44 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #3317460 by e0ipso: Libraries only attached during cold caches

parent c4607001
Loading
Loading
Loading
Loading
+6 −20
Original line number Diff line number Diff line
@@ -117,18 +117,13 @@ class TwigComponentLoader implements LoaderInterface {
    }
    $plugin_id = $component->getPluginId();
    $code = file_get_contents($path);
    $lib_build = ['#attached' => ['library' => [$component->getLibraryName()]]];
    try {
      // This is the main reason for the loader (other than finding the Twig
      // template). This will eventually add the auto-generated library into the
      // page.
      $this->renderer->render($lib_build);
    }
    catch (\Exception $e) {
      // Off-band library render failed.
    }
    $code = "{{ cl_components_additional_context('" . addcslashes($component->getId(), "'") . "', '" . addcslashes($variant ?: '', "'") . "', " . (int) ($this->twigDebug && $component->isDebugMode()) . ") }}"
    $library_name = $component->getLibraryName();
    $code = "{{ attach_library('$library_name') }}" . PHP_EOL
      . "{{ cl_components_additional_context('" . addcslashes($component->getId(), "'") . "', '" . addcslashes($variant ?: '', "'") . "', " . (int) ($this->twigDebug && $component->isDebugMode()) . ") }}"
      . PHP_EOL . $code;
    if ($component->isDebugMode()) {
      $code = "{{ attach_library('cl_components/cl_debug') }}" . PHP_EOL . $code;
    }
    if ($this->twigDebug) {
      $code = "{# start cl_component $plugin_id #}" . PHP_EOL
        . "<!-- start cl_component $plugin_id -->" . PHP_EOL
@@ -136,15 +131,6 @@ class TwigComponentLoader implements LoaderInterface {
        . "<!-- end cl_component $plugin_id -->" . PHP_EOL
        . "{# end cl_component $plugin_id #}" . PHP_EOL;
    }
    if ($component->isDebugMode()) {
      $debug_lib_build = ['#attached' => ['library' => ['cl_components/cl_debug']]];
      try {
        $this->renderer->render($debug_lib_build);
      }
      catch (\Exception $e) {
        // Off-band library render failed.
      }
    }
    return new Source($code, $name, $path);
  }