Lucifier129 / react-lite

An implementation of React v15.x that optimizes for small script size
MIT License
1.73k stars 100 forks source link

react-lite doesn't throw errors if ReactLite is loaded twice on page #119

Open rileylnapier opened 6 years ago

rileylnapier commented 6 years ago

i ran into an issue yesterday where my event handlers were all firing twice. took me long time to debug and i ended up having to revert react-lite. when i reverted, i got this error

Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

i then was able to realize i had react-lite in 2 different bundles and then fixed my problem and went back to use react-lite.

would be nice to have this error in react-lite too. thoughts?

Lucifier129 commented 6 years ago

Did you use babel-plugin-transform-react-inline-elements which included regular react?

react-lite is written by ES2015, as a UMD modules, and works with webpack alias, it is hard to load react-lite twice, and it is also hard to check that.

Maybe webpack-bundle-analyzer can help:)

rileylnapier commented 6 years ago

no, my build just creates two bundles for one page and i didn't realize both of them had react bundled. this caused some really weird errors. react throws an error in this situation and react-lite doesn't. just fyi.