Commit cb0a7995 authored by catch's avatar catch
Browse files

Issue #3390178 by godotislate, larowlan, catch, pixlkat, Utilvideo, rsnyd, Wim...

Issue #3390178 by godotislate, larowlan, catch, pixlkat, Utilvideo, rsnyd, Wim Leers, cilefen, smustgrave, fjgarlin, jakegibs617, seixas, mohithasmukh, very_random_man: big_pipe sometimes fails to load blocks

(cherry picked from commit dcf27ba1)
parent 257ca110
Loading
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -92,7 +92,10 @@
      node.nodeType === Node.ELEMENT_NODE &&
        node.nodeName === 'SCRIPT' &&
        node.dataset &&
        node.dataset.bigPipeReplacementForPlaceholderWithId,
        node.dataset.bigPipeReplacementForPlaceholderWithId &&
        typeof drupalSettings.bigPipePlaceholderIds[
          node.dataset.bigPipeReplacementForPlaceholderWithId
        ] !== 'undefined',
    );
  }

@@ -106,6 +109,13 @@
    if (checkMutation(node)) {
      processReplacement(node);
    }
    // Checks if parent node of target node has not been processed, which can
    // occur if the script node was first observed with empty content and then
    // the child text node was added in full later.
    // @see `@ingroup large_chunk` for more information.
    else if (checkMutation(node.parentNode)) {
      processReplacement(node.parentNode);
    }
  }

  /**
+7 −0
Original line number Diff line number Diff line
@@ -19,3 +19,10 @@ big_pipe_test_large_content:
    _title: 'BigPipe test large content'
  requirements:
    _access: 'TRUE'

big_pipe_test_multiple_replacements:
  path: '/big_pipe_test_multiple_replacements'
  defaults:
    _controller: '\Drupal\big_pipe_regression_test\BigPipeRegressionTestController::multipleReplacements'
  requirements:
    _access: 'TRUE'
+34 −1
Original line number Diff line number Diff line
@@ -3,12 +3,15 @@
namespace Drupal\big_pipe_regression_test;

use Drupal\big_pipe\Render\BigPipeMarkup;
use Drupal\Component\Utility\Random;
use Drupal\Core\Security\TrustedCallbackInterface;

class BigPipeRegressionTestController implements TrustedCallbackInterface {

  const MARKER_2678662 = '<script>var hitsTheFloor = "</body>";</script>';

  const PLACEHOLDER_COUNT = 3000;

  /**
   * @see \Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleBodies_2678662()
   */
@@ -46,6 +49,23 @@ public function largeContent() {
    ];
  }

  /**
   * A page with multiple nodes.
   *
   * @see \Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleReplacements
   */
  public function multipleReplacements() {
    $build = [];
    foreach (range(1, self::PLACEHOLDER_COUNT) as $length) {
      $build[] = [
        '#lazy_builder' => [static::class . '::renderRandomSentence', [$length]],
        '#create_placeholder' => TRUE,
      ];
    }

    return $build;
  }

  /**
   * Renders large content.
   *
@@ -70,11 +90,24 @@ public static function currentTime() {
    ];
  }

  /**
   * Renders a random length sentence.
   *
   * @param int $length
   *   The sentence length.
   *
   * @return array
   *   Render array.
   */
  public static function renderRandomSentence(int $length): array {
    return ['#cache' => ['max-age' => 0], '#markup' => (new Random())->sentences($length)];
  }

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return ['currentTime', 'largeContentBuilder'];
    return ['currentTime', 'largeContentBuilder', 'renderRandomSentence'];
  }

}
+23 −0
Original line number Diff line number Diff line
@@ -150,4 +150,27 @@ public function testBigPipeLargeContent() {
    $assert_session->elementExists('css', '#big-pipe-large-content');
  }

  /**
   * Test BigPipe replacement of multiple complex replacements.
   *
   * In some situations with either a large number of replacements or multiple
   * replacements involving complex operations, some replacements were not
   * completed. This is a simulation of such a situation by rendering a lot of
   * placeholders on a page.
   *
   * @see https://www.drupal.org/node/3390178
   */
  public function testMultipleReplacements(): void {
    $user = $this->drupalCreateUser();
    $this->drupalLogin($user);

    $assert_session = $this->assertSession();

    $this->drupalGet(Url::fromRoute('big_pipe_test_multiple_replacements'));
    $this->assertNotNull($assert_session->waitForElement('css', 'script[data-big-pipe-event="stop"]'));
    $this->assertCount(0, $this->getDrupalSettings()['bigPipePlaceholderIds']);
    $this->assertCount(0, $this->getSession()->getPage()->findAll('css', 'span[data-big-pipe-placeholder-id]'));
    $this->assertCount(BigPipeRegressionTestController::PLACEHOLDER_COUNT + 1, $this->getSession()->getPage()->findAll('css', 'script[data-big-pipe-replacement-for-placeholder-with-id]'));
  }

}