-
-
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
Component ignores the "key" attribute when it is the only child of another Component #254
Comments
A possible fix in my PR #255 |
@gnaeus Great catch! This is a good use of keys, it seems I have a need for this myself. It looks like the CI breakage in #255 is just saucelabs failing to connect - the tests are actually passing just fine 👍 If you don't mind, I'm going to convert your JSFiddle into a test for the PR when I merge. I will try to get this done tonight 😃 |
Ok, thanks a lot! |
@gnaeus I think the SSR fix in 6 bypassed this change. Re-opening to look into it. |
Merged for release in |
Released the fix! http://jsfiddle.net/developit/zckmzj51/5/ Sorry about the long wait on this one @gnaeus and thanks for your patience! |
When a component returns in
render()
methon only one of its chilren, for example:it ignores the
key
attributes from component's children. And then children of same type are patched in place by virtual dom algorithm instead of mounting / unmounting. Like if there are nokey
attributes at all.I now that Preact recycles DOM nodes and even components instead of render them again. But if we modify code like that:
then everethyng works fine and components are unmounted. Fore details please see JSFiddle
And it seems that in React this bug is not present. See JSFiddle
Why it is matter for me? Because I want to port my application from KnockoutJS to Preact.
Also I need some routing setup. And now I end up with followig code:
P.S. Sorry for my poor English
The text was updated successfully, but these errors were encountered: