- From: Tito <notifications@github.com>
- Date: Sun, 28 Apr 2024 12:50:51 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/1055/2081631810@github.com>
This is not needed, the browser already has this as `appendChild/removeChild/insertBefore`.
It is also not solving anything, because after the first run every tree is disconnected from each other and nobody knows which random thing we will do. I will explain.
Lets say we have the hypothetical situation of
```js
<div id="1"></div>
function Component(){
return <div id="2"></div>
}
<div id="3"></div>
```
seems to me you are proposing to solve this by something similar to
```js
<div id="1"></div>
queueDOMUpdate(function Component(){
return <div id="2"></div>
})
<div id="3"></div>
```
That will work only once. Lets imagine I have this other situation
```js
<div id="1"></div>
queueDOMUpdate(function Component(shouldShowSignal){
return shouldShowSignal() ? null : <div id="2"></div>
})
<div id="3"></div>
```
Lets say `shouldShowSignal` is false, so `queueDOMUpdate` prints nothing to the DOM. Now, if the signal changes to true, what does queueDOMUpdate does? Nothing because already ran long ago, and if you run `queueDOMUpdate` inside the component it will append the element at the end of the tree which is not where we want to append it . So how do we solve this problem? With a placeholder.
```js
<div id="1"></div>
<placeholder id="2"></div>
function Component(){
return insertBefore(<div id="2.1"></div>, placeholder)
)
<div id="3"></div>
```
If the signal toggles to other values, you can imagine the `insertBefore` works as expected and `queueDOMUpdate` has nothing to do. You cannot rely on a microtask to insert the element at the right place, you have to use placeholders. The scheduling problem is imaginary.
--
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1055#issuecomment-2081631810
You are receiving this because you are subscribed to this thread.
Message ID: <WICG/webcomponents/issues/1055/2081631810@github.com>
Received on Sunday, 28 April 2024 19:50:55 UTC