gaearon / react-proxy

Proxies React components without unmounting or losing their state
459 stars 50 forks source link

Helpful error not thrown for stateless components instantiation. #76

Open palavrov opened 7 years ago

palavrov commented 7 years ago

That one is really annoying. See gaearon/react-hot-loader#488

hfjallemark commented 7 years ago

Any update on this one? It's almost impossible to debug stateless components using react-proxy as it is today.

Panoplos commented 7 years ago

Oh my! This is the module that has me pulling my hair out!!

eirikurn commented 7 years ago

I'm happy to write a PR for this issue. I can think of the following fixes, which do you prefer @gaearon:

  1. Detect if component is a native-ish ES6 class by reading it's source with Function.prototype.toString(). Like is-class does: https://github.com/miguelmota/is-class/blob/master/is-class.js
  2. Re-throw error unless it's "Cannot call a class as a function", with a regex that softly matches the different error messages in Trident, Gecko, Blink, Webkit and Babel.

1 might be slower but more standardized (with a leaky special case for babel).

2 is simpler and perhaps good enough for this edge case, but UA error messages do sometimes change. This would also have false negatives if the component constructor calls an ES6 class without new.

bkniffler commented 7 years ago

Please fix this, its been driving me crazy and the issue is growing some serious beard now. There's been a suggestion on how to fix in the linked issue.