From 67383278e0dda48f7e321be3b77de757493dad3c 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 | 79 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/source b/source index 38287a433ad..8dbc4fd9cf3 100644 --- a/source +++ b/source @@ -2072,10 +2072,10 @@ 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 @@ -2088,8 +2088,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute 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

@@ -3195,6 +3196,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The insertion steps, removing steps, adopting steps, and + 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,22 @@ 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 abort those + steps.

    2. + +
    3. If style is not connected, then abort those steps.

    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 +15069,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 +58125,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: