Review main Merged

84742[BUGFIX] Avoid race condition in DocumentService.ready()

Benjamin Franzke CR +2 V +2 Easy +10 −34 updated 06/18/24, 13:05

Commit message

Improve document-service responsiveness by relying on
`DOMContentLoaded` and `document.readyState` >= `interactive`.

1) Handle non-loading state as "ready" to avoid waiting for `complete`.

   `document.readyState` has three states:

    * `loading`
       The document is still loading.

    * `interactive`
       The document has finished loading and the document
       has been parsed but sub-resources such as scripts, images,
       stylesheets and frames are still loading. The state indicates
       that the DOMContentLoaded event is about to fire.

    * `complete`
       The document and all sub-resources have finished loading.
       The state indicates that the load event is about to fire.

   If DocumentService.ready was called in "interactive" state we have
   been skipping this state as we only considered `complete` to be
   the "ready" state in this case.
   This is wrong as we actually wait for the DOMContentLoaded if we
   are launched in the initial readyState (`loading`), that means
   an initial `interactive` must be understood as:

     `DOMContentLoaded` has already been fired as state is `interactive`

   We should actually avoid waiting for `complete` entirely, as document
   readyState `interactive` means "ready" in terms of document parsing.
   We're not interested in images or async scripts that are still
   loading and want event listeners to be registered as early as
   possible.

   With this improvement applied we can also drop the (now) unneeded
   `load` event-listener, as we are no longer skipping interactive
   state (this made the `load`-listener necessary previously).

   Note that the `load` workaround was previously needed for IE<=10 as
   those versions set `document.readyState` to `interactive` prior to
   the `DOMContentLoaded` event. This applied workaround becomes a race
   condition once `load` never happens and that is the case with a
   recent google chrome regression which causes iframe documents to
   never "complete": https://issues.chromium.org/issues/347724924

2) Drop the timeout logic. It is no longer needed now that we only need
   to wait for `DOMContentLoaded` – which will always fire (or already
   fired) – instead of the `load` event.

3) Avoid creation of new promises for every invocation of the
   ready-method. A promise can be reused without side effects by
   multiple consumers. This avoids creating a lot of event listeners
   (and previously timers).

4) Remove unneeded document and window references.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Oli Bartsch +1
    • Andreas Kienast +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Jasmina Ließmann +1
    • Oli Bartsch +1
    • Andreas Kienast +1
    • core-ci +1 CI

Issues 2

Files 2

Review log 1317

  1. Benjamin Franzke uploaded patch set 1 06/18/24, 04:24

  2. core-ci voted on patch set 1 V +1 06/18/24, 04:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59763

  3. Benjamin Franzke uploaded patch set 2 V +1 06/18/24, 04:35

  4. core-ci voted on patch set 2 V +1 06/18/24, 04:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59765

  5. Andreas Kienast voted on patch set 2 CR +1 06/18/24, 06:02

  6. Benjamin Franzke uploaded patch set 3 CR +1 V +1 06/18/24, 06:07

  7. core-ci voted on patch set 3 V +1 06/18/24, 06:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59773

  8. Benjamin Franzke commented on patch set 3 CR -1 06/18/24, 06:27

    Considerung to switch to BUGFIX and also target v11, as this effects newer chrome releases (126.0.6478.62 affected, 126.0.6478.61 not affected), but need to perform some more tests.
  9. Benjamin Franzke updated the commit message in patch set 4 CR -1 V +1 06/18/24, 09:51

  10. Benjamin Franzke commented on patch set 4 06/18/24, 09:52

    Reply

    Done
  11. core-ci voted on patch set 4 V +1 06/18/24, 09:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59791

  12. Jasmina Ließmann voted on patch set 4 V +1 06/18/24, 10:51

  13. Jasmina Ließmann commented on patch set 4 06/18/24, 11:00

    Works on Windows 10 and latest Chrome version.
  14. Oli Bartsch voted on patch set 4 CR +1 V +1 06/18/24, 12:29

  15. Andreas Kienast voted on patch set 4 CR +1 V +1 06/18/24, 12:45

  16. Benjamin Franzke commented on patch set 4 CR +2 V +2 06/18/24, 12:58

    Thanks for your votes, please vote "I am impacted" on https://issues.chromium.org/issues/347724924
  17. Benjamin Franzke merged patch set 5 06/18/24, 13:05