Large placeholders are not processed

Created on 13 September 2023, about 1 year ago
Updated 11 October 2023, about 1 year ago

Problem/Motivation

Large placeholders are not rendered. By large I mean let's say 1.5MB of data, but on our site, it was a chunk of 300kb with an exception.

Steps to reproduce

In #3196973 we introduced the ability to use MutationObserver API. The problem here is in the following:
1. The Observer is configured with only one option childList: true which means that it will only look for new children.
2. If the server returns a large chunk of data it is streamed and may not be fully loaded at the moment when the Mutation observer is triggered.
3. Afterwards it will simply try to parse JSON which will not be valid at the moment and never re-try to check it again.

    const response = mapTextContentToAjaxResponse(content);

    if (response === false) {
      return;
    }

So, here is how to reproduce it on barebones Drupal.
Place a custom block with long text that has more than 1.5MB ( I didn't test how small should be text, just put inside a large text ) and make sure that block will not be cacheable, either using block_alter hook or using for instance blocache mobule, so the block will be lazy builded

I thought Simplitest will work more than one day.

Proposed resolution

So there are a lot of possible solutions. I'll attach two patches for the 1-st and 2-st solutions.

  1. Is to track all nodes that have invalid JSON
        if (response === false) {
          HERE WE PUT A NODE INTO AN ARRAY
          return;
        }
    

    And on DOMContentLoaded process them all.

    <!--break-->

    With such an approach we are sure that everything will be rendered but at the end of the page loading.

  2. The second approach Is to add additional configuration options to MutationObserver and rework it a bit. Buy this I mean:
    • To add subtree: true, characterData: true configuration optoins. It will ensure that the observer will be triggered each time text node inside subtree nodes is changed. This is actually what we need because this will track changes made to text nodes (by text node I mean the response of a placeholder that is partially present inside script placeholder node.)
    • Rework a bit how we process mutations so it will also track changed made to characterData mutation type

    In such a way, we will ensure that a placeholder will be rendered as soon as the browser fully loads it. I'm not sure about performance issues with such implementation.

  3. Another solution would be to revert changes made in #3196973. And drop MutationObserver usage for placeholder processing.

Remaining tasks

Decide which solution is suitable.

User interface changes

-

API changes

-

Data model changes

-

Release notes snippet

-

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
BigPipeΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡ΊπŸ‡¦Ukraine dinazaur

Live updates comments and jobs are added and updated live.
  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024