Commit 5dcbaebe authored by catch's avatar catch
Browse files

task: #3626105 Release runtime theme registries after destruction

By: ptmkenny
By: nicxvan
(cherry picked from commit 96cfe413)
parent 8e8418bc
Loading
Loading
Loading
Loading
Loading
+4 −1
Changes for core/lib/Drupal/Core/Theme/Registry.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -770,7 +770,10 @@ public function reset() {
   * {@inheritdoc}
   */
  public function destruct() {
    foreach ($this->runtimeRegistry as $runtime_registry) {
    // Release the registries so later requests get fresh runtime collectors.
    $runtime_registries = $this->runtimeRegistry;
    $this->runtimeRegistry = [];
    foreach ($runtime_registries as $runtime_registry) {
      $runtime_registry->destruct();
    }
  }
+22 −0
Changes for core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -56,6 +56,28 @@ public function testRaceCondition(): void {
    $this->assertNotEmpty($registry->get('theme_test_template_test_2'), 'Offset was returned correctly from the theme registry');
  }

  /**
   * Tests that runtime theme hooks remain available after registry cleanup.
   */
  public function testRuntimeRegistryAfterDestruct(): void {
    \Drupal::request()->setMethod('GET');
    $registry = $this->container->get(Registry::class);
    $runtime_registry = $registry->getRuntime();
    $hook = 'theme_test_template_test';

    $this->assertTrue($runtime_registry->has($hook));
    $definition = $runtime_registry->get($hook);
    $this->assertNotEmpty($definition);

    // Persistent workers may keep the service alive after cleanup.
    $registry->destruct();
    $next_runtime_registry = $registry->getRuntime();

    $this->assertTrue($next_runtime_registry->has($hook));
    $this->assertSame($definition, $next_runtime_registry->get($hook));
    $this->assertNotSame($runtime_registry, $next_runtime_registry);
  }

  /**
   * Tests the theme registry with multiple subthemes.
   */