Open
Description
I am using Surplus.content
directly to manipulate the content of an element not created or controlled by the Surplus compiler. But the same error can be reproduced with JSX syntax. The following snippet reproduces the error.
import * as Surplus from "surplus";
const a = ["foo ", span("["), "bar", span("]")];
const b = ["foo ", span("{"), "bar", span("}")];
let state = [];
const body = document.createElement("div");
state = Surplus.content(body, a, state);
state = Surplus.content(body, b, state);
// Failed to execute 'insertBefore' on 'Node':
// The node before which the new node is to be
// inserted is not a child of this node.
// utility
function span(s: string) {
const span = document.createElement("span");
span.innerText = s;
return span;
}
The exception is thrown from https://github.com/adamhaile/surplus/blob/master/src/runtime/content.ts#L302. It appears that inserting the right-most <span>}</span>
is skipped, due to being marked as NOINSERT
. Then, when going to insert the Text node "bar"
, it attempts to insert relative to the <span>
which was not inserted.
I'm not sure why the right-most <span>
is marked as NOINSERT
by this line in the text node reuse algorithm. Is it failing to mark the "bar"
node and mis-marking the <span>
node?
Metadata
Assignees
Labels
No labels
Activity