-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Rendering components with identical children into the same parent container breaks #126
Comments
Ah - looks like this has to do with one of the components being high-order and the other not. |
@hatched Quick fix for this (at least for your example) would be to not rely on Instead, I'd recommend using the returned root node from let root;
let components = [Index, Join, Index, Join, Index]
// This loop simulates the user navigating forward and backwards over two components.
components.forEach(function(Cmp) {
root = render(
<Cmp data={window.preactProps} />,
document.body,
root)
}) This accounts for the case where render() destroys the previous rendered root. I'm working on a lower-level fix for this, in case the explanation above only solves your reproduction and not the bug as you ran into it (let me know). |
Thanks for the quick reply! Because this is being first rendered on the server I had to initialize function renderParent(Component) {
let root = document.body.firstChild
root = render(
<Component data={window.preactProps} />,
document.body,
root)
} |
Perfect. Now I'm a little stuck: should I keep the fix I just added that checks before invoking |
I think that it is always a good idea to code defensively and it is a quite small change so unless there are some unintended consequences that I'm not aware of I'd vote to keep it in. |
True, it's literally 2 bytes after gzip. I shouldn't agonize over these things so much, haha. |
I'm going to close this issue out for now since we've got a solution, though I'll likely re-reference it when I address making edit: for reference, reproduction I was using to test: http://jsfiddle.net/developit/t8p15pps/ |
If you try to render two different components into the same parent container multiple times with shared child components the browser will throw an error:
Uncaught HierarchyRequestError: Failed to execute 'replaceChild' on 'Node': The new child element contains the parent.
Chrome Version 50.0.2661.75 (64-bit)
This is easier to explain with some code:
The text was updated successfully, but these errors were encountered: