Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconcileArrays fails on parent.insertBefore #92

Open
webstrand opened this issue Jun 8, 2021 · 0 comments
Open

reconcileArrays fails on parent.insertBefore #92

webstrand opened this issue Jun 8, 2021 · 0 comments

Comments

@webstrand
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant