ReactTraining / react-broadcast

Reliably communicate state changes to deeply nested React elements
MIT License
1.32k stars 58 forks source link

createContext: uid clash when developing npm linked packages #52

Open Andarist opened 6 years ago

Andarist commented 6 years ago

Each npm linked package has its own set of node_modules, therefore there might be multiple copies of react-broadcasts required by an app (all with the same version). Each of them ofc maintains its own uid counter but broadcasts is a shared key on legacy context and all those copies override what the put in context.

Don't have better idea on how to deal with it than randomizing broadcasts key (at least in development), thoughts? Can prepare a PR handling this if you find it worthwhile.

mjackson commented 6 years ago

The best solution would be to use a Symbol, but I'm not sure about the best way to support browsers that don't have it, like IE 11.

Andarist commented 6 years ago

Me neither 😉This could be used in development mode only though, npm link rather shouldnt be used in production environments.