This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-12
Channels
- # admin-announcements (2)
- # aleph (2)
- # arachne (16)
- # beginners (33)
- # boot (20)
- # bristol-clojurians (6)
- # capetown (4)
- # cider (50)
- # clojure (74)
- # clojure-austin (4)
- # clojure-canada (1)
- # clojure-china (2)
- # clojure-czech (1)
- # clojure-greece (1)
- # clojure-poland (4)
- # clojure-quebec (5)
- # clojure-russia (5)
- # clojure-spec (34)
- # clojure-uk (45)
- # clojurescript (131)
- # cursive (4)
- # datascript (2)
- # datomic (9)
- # editors (2)
- # emacs (2)
- # hoplon (173)
- # jobs (5)
- # lein-figwheel (3)
- # leiningen (1)
- # off-topic (1)
- # om (44)
- # onyx (8)
- # proton (10)
- # re-frame (81)
- # reagent (23)
- # untangled (57)
- # vim (2)
- # yada (8)
I dont get this one. I have two factories inside a div, both are instanciating a seperate component. If I give both a unique :keyfn they dont render because of children sharing same key. But if I only give one :keyfn, then it stops complaining. So this does not work:
(def search-query (om/factory SearchQuery {:keyfn :search-query}))
(def search-results (om/factory SearchResults {:keyfn :search-results}))
But this will (and vice versa with search-results carrying a :keyfn)
(def search-query (om/factory SearchQuery {:keyfn :search-query}))
(def search-results (om/factory SearchResults))
What I've noticed is that if React is not given a function to create the key then $null
is put on the end of the key that it makes up. $null
will be different to say what :search-query
returns.
https://github.com/omcljs/om/issues/673 is that related to this issue then @cjmurphy ?
@dnolen: Makes sense why the example in that github issue is different to my own using the current om.
The fn returned by factory
is like having build
in an anonymous function?
@dominicm: almost, factory returns a constructor fn which has the same shape as normal React DOM constructor fns
@hlolli: sounds like it's possible both of the keyfns might return nil
so then you would have the same key?
ah, that makes sense. Close enough in utility. Makes sense that issue is reported in both versions.
yeah I need to look more closely at 673 - we used undefined specifically to get React to ignore but maybe something changed in React internally that makes that not work anymore
@dnolen: My understanding based on the log messages is that React is now doing (= undefined undefined)
and collapsing the children as being the same.
I wonder if this means that React is using something like hasOwnKey
instead of (not= component[key] undefined)
---
I just realised that I just made a horrible mess of blending js and cljs to make pseudo code. Not sure if that's good or bad.
@hlolli: k right, so yes probably related to 673, will try to look at that later in the afternoon
ok, just to flood, then this is the error message. @dnolen cool!
Encountered two children with the same key, `null`. Child keys must be unique; when two children share a key, only the first child will be used.
yes, it would save sanity to allow nil to be a valid key. I guess react only complains about siblings being duplicated.
but then the question is, why keyfn doesnt associate the assigned key. Yes, which is strange.
if both are siblings lack :keyfn or both have one, it fails, if one is different than other, it works.
@hlolli: because in one case it the key is nil
in the other case the key is undefined
which React ignores
@hlolli: look at elements in chrome developer console. Every element has a data-reactid
. You will see how they are made up with your examples. I know that's not a theoretical answer, but doing that always gets me out of trouble and it seems simple enough to make sure all sibling elements have a different data-reactid
. Always proving a function seems like a good idea as well. I know not completely answering your question 🙂
@cjmurphy Thanks, good to know. I always make sure that when creating elements with cljs functions to give :key
wherever possible. That way at least I lose all warning, which is nice.
Yeah, directly :key
for dom elements and :keyfn
for om next components. I think you will be able to see them all in the developer console, even the ones not being displayed because they are duplicates. Not 100% on that thou.
@dnolen: @dominicm: #673 is present in React 15 but not in React 14. Previously setting key
to undefined
would count as an absent key, but in React 15 key
s are explicitly set to undefined
this is what I’ve gathered from looking at the issue a few weeks ago. A few things might have changed meanwhile
@anmonteiro: ok good to know, well in anycase just conditionally adding key
should cover us, simple enough to do
Yeah, I think that would be the fix
@dnolen: meanwhile, I’ll try upgrading React to 15.2 to see if this has been eventually fixed/changed upstream
@anmonteiro: cool, yeah would be interested in hearing about that