From 0b507c1605782a8ff6dac950c2ac4908ab24e19b 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 | 92 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/source b/source index 38287a433ad..784bde10531 100644 --- a/source +++ b/source @@ -2072,24 +2072,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,12 +2098,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute connected and its shadow-including root has a browsing context. 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 becomes browsing-context disconnected either when the removing steps are invoked with it as the argument and it - is now no longer browsing-context connected, or when its shadow-including - root no longer has a browsing context. + data-x="concept-node-insert-ext">insertion steps are invoked with it as the first argument + and it is now 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 connected, or when its + shadow-including root no longer has a browsing + context.

Scripting

@@ -3194,7 +3195,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The pre-insert, insert, append, replace, replace all, remove, and adopt algorithms for nodes
  • The insertion steps, removing steps, - adopting steps, and + adopting steps, + children added steps, and child text content change steps hooks for elements
  • The change, append, remove, replace, and set value algorithms for attributes
  • The attribute change steps hook for attributes
  • @@ -15043,8 +15045,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:

    @@ -15053,8 +15068,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 child text content change steps run.

  • @@ -58110,24 +58124,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:

    - +

    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: