Raise a Callback When Complete

Created on 11 December 2020, about 4 years ago
Updated 30 January 2023, almost 2 years ago

Problem/Motivation

I'd like for BigPipe to raise a function to let all other modules know that it is done rendering all DOM elements to the page, so other modules can know when they're able to run their own Javascript/jquery manipulation on those elements. Without this callback in place, JS that is run on $(window).on("load") or $(document).ready won't be able to manipulate elements that aren't yet available to it.

Proposed resolution

I've posted a simple patch file that adds JS to core\modules\big_pipe\js\big_pipe.js, creating and raising an event called "bigPipeProcessDocumentComplete" that will be callable from anywhere else.

Update to big_pipe.js:

  function bigPipeProcessDocument(context) {
    if (!context.querySelector('script[data-big-pipe-event="start"]')) {
      return false;
    }

    $(context).find('script[data-big-pipe-replacement-for-placeholder-with-id]').once('big-pipe').each(bigPipeProcessPlaceholderReplacement);

    if (context.querySelector('script[data-big-pipe-event="stop"]')) {
      if (timeoutID) {
        clearTimeout(timeoutID);
      }
      const event = new Event('bigPipeProcessDocumentComplete');
      window.addEventListener('bigPipeProcessDocumentComplete', function (e) {}, false);
      window.dispatchEvent(event);
      return true;
    }

    return false;
  }

Which will now be callable elsewhere by using:

    $(window).on('bigPipeProcessDocumentComplete', function () {
      console.log("run this code when bigPipeProcessDocumentComplete...");
    });
✨ Feature request
Status

Needs work

Version

9.5

Component
AjaxΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States ryankavalsky

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.71.5 2024