Commit b4c28903 authored by Travis Tomka's avatar Travis Tomka
Browse files

Issue #3162070 by droath: Only create the component once and cache the instance for future calls

parent d55f0077
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@ class JSComponentBlockType extends BlockBase implements ContainerFactoryPluginIn
   */
  protected $componentRootId;

  /**
   * @var \Drupal\js_component\Plugin\JSComponent
   */
  protected $componentInstance;

  /**
   * @var LibraryDiscoveryInterface
   */
@@ -345,12 +350,16 @@ class JSComponentBlockType extends BlockBase implements ContainerFactoryPluginIn
   * @return \Drupal\js_component\Plugin\JSComponent
   */
  protected function getComponentInstance() {
    return $this->jsComponentManager
    if (!isset($this->componentInstance)) {
      $this->componentInstance = $this->jsComponentManager
        ->createInstance($this->getComponentPluginId(), [
          'overrides' => $this->getConfigurationOverrides()
        ]);
    }

    return $this->componentInstance;
  }

  /**
   * Get the component attachments.
   *