sinuous icon indicating copy to clipboard operation
sinuous copied to clipboard

Live Fragment Issue

Open skethan opened this issue 3 years ago • 3 comments

I am having issues if I update the view with fragments. Eg: https://stackblitz.com/edit/vitejs-vite-uj6g1b?file=main.jsx

skethan avatar Sep 03 '22 16:09 skethan

This isn't an issue with Sinuous - it's how document fragments work: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment#usage_notes says:

[It's common to] insert the fragment into the DOM using Node interface methods such as appendChild(), append(), or insertBefore(). Doing this moves the fragment's nodes into the DOM, leaving behind an empty DocumentFragment.

Note that Sinuous will silently append items of arrays so <div>{[1,2,3]}</div> is <div>1 2 3</div> (as text nodes in this case). This means <>{n}</> will create a document fragment and then append each element of n into it, which empties the fragments (see above MDN quote).

You can see this in your browser console:

image

The first log, before rendering, shows items in the fragment. Immediately after calling <App/>, those fragments are now empty.

tsugabloom avatar Sep 06 '22 16:09 tsugabloom

Using real elements will work for you, since calling Node methods (append, appendChild, etc) will move the element around.

image

tsugabloom avatar Sep 06 '22 16:09 tsugabloom

@heyheyhello yes thanks i understood.

kethan avatar Sep 15 '22 01:09 kethan