-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
render
appends instead of replacing
#24
Comments
Hi Leo! Preact's render is just a slight bit different in that regard, because it does not mark the DOM with data-attributes. Instead, render() accepts an optional third argument that is the root element to replace. So, to emulate react's behavior just do:
I can look into making this the default since its an inconsistency. At the very least, its something that Thanks! |
Thanks for the fast response! I'll try that out |
Is there any way to reuse element rendered on server side with preact-render-to-string? The following code is appending second element becouse It's expecting component created by preact
|
@kucharzyk: The code you pasted should work, so I investigated and found an issue. The fix is released in preact |
Just in case any others trip up on this one, I was running into duplicates but it was down to The solution was to target the child directly http://codepen.io/anon/pen/AXPqrk?editors=1010 Or simply strip the white space between parent and child elements if using |
@mikestead Good call, thanks for leaving the note. If it's only a text or comment node and you're expecting an Element, you could also try |
@developit Hi, const menuList = ReactDOM.findDOMNode(this.menuList);
if (menuList && menuList.firstChild) {
menuList.firstChild.focus();
}
Is there something I can do? |
You're accessing firstChild before the child has been added. Use a later lifecycle callback or wrap it in a timeout. |
when using children[0] / firstElementChild everything works fine. |
Looks like |
React: http://codepen.io/anon/pen/LGdaMd
Preact: http://codepen.io/anon/pen/GoxePz
Expected: print
2
on screenActual: prints
1
and2
on screenThis prevents a correct comparison in the vdom benchmark because it causes the update benchmarks to measure the cost of full creation of a tree instead: http://vdom-benchmark.github.io/vdom-benchmark/
The text was updated successfully, but these errors were encountered: