-
For this code I just want the function Collapse({isOpen, keepMounted} = props, ...rest: ChildDom[]) {
return div({ class: "Collapse"}, rest);
} I want the I have tried Tried something like this but does not appear to be working div(
{ class: Classes.COLLAPSE_BODY },
van.bind(toState(props.isOpen), (flag) => {
console.debug({ flag });
return flag ? div(...rest) : undefined;
})
) This too (this one prints only once to the console) van.bind(toState(props.isOpen), (flag) => {
console.debug({ flag });
return flag ? div({ class: Classes.COLLAPSE_BODY }, rest) : undefined;
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Could you show me the full code as well as the stacktrace of the problem? |
Beta Was this translation helpful? Give feedback.
-
Regarding your example https://stackblitz.com/edit/vitejs-vite-kc1gr9?file=src%2Fblueprint%2Fcomponents%2FCollapse.ts%3AL54, without knowing how Here is a minimalist example that can reproduce the error: <body>
<script type="text/javascript" src="https://vanjs.org/code/van-0.11.10.nomodule.debug.js"></script>
<script>
const {div} = van.tags
const dom = div("Test")
van.add(document.body, dom)
// This line will throw an error because `dom` has already been connected to the document tree
const newDom = div(dom, "Test2")
van.add(document.body. newDom)
</script>
</body> |
Beta Was this translation helpful? Give feedback.
Regarding your example https://stackblitz.com/edit/vitejs-vite-kc1gr9?file=src%2Fblueprint%2Fcomponents%2FCollapse.ts%3AL54, without knowing how
Collapse
is being called, it's not possible to say in details how did the error occur. However, by learning from the error message, I can tell the error is caused by trying to compose a DOM node that has already been connected to the document tree as the child node of something you want to build. This is an undefined behavior in VanJS, and an error with that message will be thrown whenvan-{VERSION}.debug.js
is being used. You can refer to this section https://vanjs.org/tutorial#dom-nodes-already-in-the-document-tree-can-t-be-used-as-children for…