Commit fe299100 authored by catch's avatar catch
Browse files

fix: #3564880 BigPipe placeholders with identical IDs are not all replaced

By: drumlin44
By: artem_kondra
By: godotislate
By: longwave
By: fathershawn
(cherry picked from commit 9091188c)
parent 8b702713
Loading
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -54,17 +54,14 @@
     *   An optional selector string.
     */
    insert({ data, method, selector }) {
      const target = htmx.find(selector);
      const targets = htmx.findAll(selector);

      // In rare circumstances, the target may not be found, such as if
      // the target is in a noscript element.
      if (target === null) {
      // In rare circumstances, the targets may not be found, such as if
      // the targets are in noscript elements.
      if (!targets || !targets.length) {
        return;
      }

      // Detach behaviors.
      htmx.trigger(target, 'htmx:drupal:unload');

      // Map jQuery manipulation methods to the DOM equivalent.
      const styleMap = {
        replaceWith: 'outerHTML',
@@ -74,11 +71,15 @@
        append: 'beforeend',
        after: 'afterend',
      };
      targets.forEach((target) => {
        // Detach behaviors.
        htmx.trigger(target, 'htmx:drupal:unload');

        // Make the actual swap and initialize everything.
        htmx.swap(target, data, {
          swapStyle: styleMap[method] || 'outerHTML',
        });
      });
    },

    /**
+1 −1
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ public static function counter() {
    $count++;

    return [
      '#markup' => BigPipeMarkup::create("<p>The count is $count.</p>"),
      '#markup' => BigPipeMarkup::create("<p class=\"multiple-occurrence-instance\">The count is $count.</p>"),
      '#cache' => ['max-age' => 0],
    ];
  }
+13 −0
Original line number Diff line number Diff line
@@ -209,4 +209,17 @@ protected function doInlineScriptTest(): void {
    $assert_session->elementExists('css', 'div.container-after');
  }

  /**
   * Tests that all occurrences of the same placeholder are replaced.
   */
  public function testMultipleOccurrences(): void {
    \Drupal::service('module_installer')->install(['big_pipe_test']);
    $user = $this->drupalCreateUser();
    $this->drupalLogin($user);
    $assert_session = $this->assertSession();
    $this->drupalGet(Url::fromRoute('big_pipe_test_multi_occurrence'));
    $this->assertNotNull($assert_session->waitForElement('css', 'script[data-big-pipe-event="stop"]'));
    $assert_session->elementsCount('css', 'p.multiple-occurrence-instance', 3);
  }

}