From 11f12721e23c57376a17afebf624ce71049ea80a Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 10 Feb 2019 11:55:44 +0100 Subject: [PATCH] Use the new definition of the insertion steps https://github.com/whatwg/dom/pull/732 We defer preparing scripts and updating style blocks during insertion to make sure all DOM mutations are finished before executing scripts. This is what Chrome and Firefox seem to already do anyway. --- source | 78 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/source b/source index 017248f5311..d65ecc6c613 100644 --- a/source +++ b/source @@ -2071,24 +2071,24 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

A node A is inserted into a node B when the insertion steps are invoked with - A as the argument and A's new parent is B. Similarly, a node A is removed from a node B when the - removing steps are invoked with A as the - removedNode argument and B as the oldParent argument.

+ A as the first argument and A's new parent is B. Similarly, a + node A is removed from a node B when + the removing steps are invoked with A as + the removedNode argument and B as the oldParent argument.

A node is inserted into a document when the insertion - steps are invoked with it as the argument and it is now in a document tree. - Analogously, a node is - removed from a document when the removing - steps are invoked with it as the argument and it is now no longer in a document - tree.

+ steps are invoked with it as the first argument and it is now in a document + tree. Analogously, a node is removed from a document when the removing steps are invoked with it as the argument and it + is now no longer in a document tree.

A node becomes connected when the insertion steps are invoked with it as the argument and it - is now connected. Analogously, a node insertion steps are invoked with it as the first argument + and it is now connected. Analogously, a node becomes disconnected when the removing steps are invoked with it as the argument and it is now no longer connected.

@@ -2098,7 +2098,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute browsing context is non-null. A node becomes browsing-context connected when the insertion steps are invoked - with it as the argument and it is now browsing-context connected. A node browsing-context connected. A node becomes browsing-context disconnected either when the removing steps are invoked with it as the argument and it is now no longer browsing-context @@ -15193,8 +15193,21 @@ interface HTMLStyleElement : HTMLElement {
-

The user agent must run the update a style block algorithm whenever - one of the following conditions occur:

+

To run the insertion steps for a + style element with style and deferredStepsQueue, the user + agent must act as follows:

+ +
    +
  1. If style is on the stack of open elements, then return.

  2. + +
  3. If style is not connected, then return.

  4. + +
  5. Enqueue the steps to update + style to deferredStepsQueue.

  6. +
+ +

Additionally, the user agent must run the update a style block + algorithm whenever one of the following conditions occur:

@@ -15203,8 +15216,7 @@ interface HTMLStyleElement : HTMLElement { parser or XML parser.

  • The element is not on the stack of open elements of an HTML - parser or XML parser, and it becomes connected or disconnected.

  • + parser or XML parser, and it becomes disconnected.

  • The element's children changed steps run.

  • @@ -58529,24 +58541,30 @@ o............A....e
    -

    When a script element that is not marked as being "parser-inserted" - experiences one of the events listed in the following list, the user agent must - immediately prepare the script - element:

    +

    To run the insertion steps for a + script element with script and deferredStepsQueue, the user + agent must act as follows:

    -
      +
        +
      1. If script is marked as being "parser-inserted", then + return.

      2. -
      3. The script element becomes connected.
      4. +
      5. If script is not connected, then return.

      6. -
      7. The script element is connected and a node or document fragment is - inserted into the script element, after any - script elements inserted at that time.
      8. +
      9. Enqueue the steps to prepare + script to deferredStepsQueue.

      10. +
      -
    • The script element is connected and has a src attribute set where previously the element had no such - attribute.
    • +

      To run the children changed steps for a script element with + script and deferredStepsQueue, the user agent must run the insertion steps with script and + deferredStepsQueue.

      -
    +

    Additionally, when a script element that is not marked as being + "parser-inserted" is connected and has a src attribute set where previously the element had no such + attribute, the user agent must immediately prepare the script element.

    To prepare a script, the user agent must act as follows: