節点の切断

削除 (節点)

[11] DOM木上の親節点子節点親子関係を解消することを、 子節点削除 (remove) といいます。

[12] 節点削除しても、節点が消滅するわけではありません。 何らかの参照が存在する限りは旧親節点も旧子節点ごみ収集されずに存続します。

[102] 文書から削除 (remove from a document) するとは、 文書子孫ではない状態にすることをいいます。

仕様書

削除

[6] DOM Standard 仕様書上の操作削除 (remove) >>7 は次の箇所から呼び出されています。

[9] この操作では、DOM木上の親節点子供のリストからの節点削除に加えて、 関係する範囲の状態の変更や、 MutationObserver の実行の準備も行われます (MutationObserver の実行そのものはこの時点ではなされません)。

[10] 削除手順 (>>2) も呼び出されます。

[20] blur が発生する可能性もありますが、どのタイミングかは不明です。

削除手順

[2] 節点が他の節点子供から削除されると、 その影根を含む子孫それぞれについて、 影根を含む木順削除手順群 (removing steps) >>1 が呼び出されます。

[3] DOM Standard 上のアルゴリズムである replace, replace all, remove から呼び出されます。

[4] このフックによって次の節点が何らかの処理を行います。

[5] 仕様上明確には規定されていませんが、次の動作もこのフックのタイミングで処理されると思われます。

[25] disconnectedCallback の呼び出しは、仕様書上は削除手順群ではなく、 削除手順群の直後の別の処理として定義されています。

[37] 必要な場合、 子供達変更済手順群も実行されます。 これも削除手順群とは別の処理として定義されています。

文書から削除

[111] 節点文書中でなくなることを、 文書から節点が削除される (remove a node from a document) といいます >>101

[107] 次の要素ごとの処理が定義されています。

[108] 他に、 embedappletframe については仕様上 in a Document を使って半ば宣言的に規定されていますが、 実質的に「要素の文書からの削除」の処理に該当します。

[30] フォーム被関連付け要素の削除の処理は、なぜか節点の切断と少し条件が違っていますが、 理由は不明です。

[109] 「※」のあるものは、構文解析器による挿入で特別扱いされるもので、 開いている要素のスタックからの除去で挿入時の処理が行われるかもしれませんが、 同時に削除が発生するならその処理は行われるべきではないと考えられます。 (構文解析器による削除は frameset による置き換えでしか発生しないはずです。 AAA では同じの内部の移動しか起こらないはず...)

[29] 「☆」のあるものは、切断された (becomes disconnected) 、 すなわち削除手順群影を含む文書中でなくなった時 >>28 に処理するべきものです。

[34] 「★」のあるものは、閲覧文脈切断された (browsing-context disconnected) 、 すなわち削除手順群閲覧文脈接続状態でなくなった時 >>28 に処理するべきものです。

関連

[106] 逆の状況である「要素を文書に挿入」もあります。

歴史

[16] 削除手順は、 >>15 までは節点の削除 (node is removed) と呼ばれていました。

[18] HTML Standard では現在でも「nodes are removed」と呼ばれていますが、 DOM Standard の「removing steps」を参照するようになっています >>17, >>19

[103] 要素根要素文書根要素から他の要素に変更されることを、 文書から削除 (removed from a document) されたといいます >>101

[104] この定義では文書根要素文書から削除された時が該当するのか不明瞭です (「他の」要素には変更されていない)。他の定義との整合性を考えると、 該当すると考えるべきとも思えます。

[21] Fix #34: invoke insertion/removing steps for descendants · whatwg/dom@5ec535e ( 版) https://github.com/whatwg/dom/commit/5ec535e56111d600b8afe89d0b4f709ab844461e

[23] Shadow: run insertion and removing steps also for shadow trees · whatwg/dom@2d5aaed ( 版) https://github.com/whatwg/dom/commit/2d5aaed1f525561a2c92b4e23ae2b7e6ff8244ad

[22] Only pass oldParent to removing steps for the node actually removed · whatwg/dom@baf4e6e ( 版) https://github.com/whatwg/dom/commit/baf4e6e83e473330e5b073df77c091815489bb81

[112] Editorial: synchronize with the DOM Standard · whatwg/html@21c6ec7 ( 版) https://github.com/whatwg/html/commit/21c6ec77594eb89b836d4872222f5916910967fd

[24] Add support for custom elements · whatwg/dom@7f63535 ( 版) https://github.com/whatwg/dom/commit/7f63535da39a1cbf7f8f68563abc6f05f760990a

[26] Generalize inserted/removed into/from a document algorithms · whatwg/html@8da5a18 ( 版) https://github.com/whatwg/html/commit/8da5a18b447290ffcdd6c23e268a6e75f906c684

[27] Execute <script> in shadow trees · whatwg/html@caf203f ( 版) https://github.com/whatwg/html/commit/caf203fd4d9a5047d1ff2edad2290d53e21368ba

[31] Integrate with the Referrer Policy spec, part 1 of n ( (domenic著, )) https://github.com/whatwg/html/commit/6a7318072f340ad45229df171245d70d8621c2fe

[32] Align with vocabulary changes in the DOM Standard (annevk著, ) https://github.com/whatwg/html/commit/5b9c5d5a39c38b08e5a5c9334e14804f063235b2

[33] Make <link rel="stylesheet"> work inside shadow trees (domenic著, ) https://github.com/whatwg/html/commit/43c57866c2bbc20dc0deb15a721a28cbaad2140c

[35] Editorial: update variable name in removing steps (foolip著, ) https://github.com/whatwg/fullscreen/commit/c8164afaa1a04b77c9b45f013144c603f3e201bd

[36] Add child text content and its change steps (domenic著, ) https://github.com/whatwg/dom/commit/93db3408c360a958c2f1c00fbb99bf6c5d6fa5b2

[38] Make slots do nothing outside shadow trees (hayatoito著, ) https://github.com/whatwg/dom/commit/8f8c1c30c39be38480336e7fc39c1cc7b40b6a83

[39] Shadow: Specify when `slotchange` fires · Issue #447 · whatwg/dom () https://github.com/whatwg/dom/issues/447

[40] Track HTML parser form-associated elements with a flag (annevk著, ) https://github.com/whatwg/html/commit/384c30c56d6dfd26dfbd3a5024ae10e7f7134483

[41] Meta: add id=removing-steps for linkability of the removing steps (foolip著, ) https://github.com/whatwg/fullscreen/commit/e1fb3a82b6d794bc9fb165f7e2a95e1a0b51176b

[42] Meta: add id=removing-steps for linkability of the removing steps by foolip · Pull Request #127 · whatwg/fullscreen () https://github.com/whatwg/fullscreen/pull/127

[43] Editorial: a removed node's root is itself (annevk著, ) https://github.com/whatwg/dom/commit/42d2485c4f84fb210452ca53e07503229716b147

[44] Assign slotables for a tree should be invoked on node and not node's root in node remove · Issue #691 · whatwg/dom () https://github.com/whatwg/dom/issues/691

[45] Editorial: a removed node's root is itself by annevk · Pull Request #692 · whatwg/dom () https://github.com/whatwg/dom/pull/692

[46] Replace child text content change steps (annevk, , ) https://github.com/whatwg/dom/commit/ce4c6ba5b6e8e26e9c0e6f157243df9942d8b52a

[47] Editorial: remove parent argument to remove (annevk, , ) https://github.com/whatwg/dom/commit/37d847525782a2a6692aba5fb9ad0e9c419a13ff

[48] Editorial: remove parent argument to remove · Issue #801 · whatwg/dom () https://github.com/whatwg/dom/issues/801

[49] Editorial: remove parent argument to remove by annevk · Pull Request #804 · whatwg/dom () https://github.com/whatwg/dom/pull/804

[50] Editorial: remove parent argument to remove · Issue #801 · whatwg/dom () https://github.com/whatwg/dom/issues/801