-
Notifications
You must be signed in to change notification settings - Fork 50
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
ES7 property initializers disappear when combined with certain decorator functions #23
Comments
Can you please add a failing test to react-proxy? |
No problem -- I'll try to get something written this weekend. |
I couldn't reproduce the problem in isolation -- it occurs when In a nutshell: Decorators execute in the order opposite that they appear, and This means that the proxied version of the class is actually what's passed to Since There are at least two potential fixes:
Either one of these will fix this particular issue, but I get the feeling both fixes should be applied; what do you think? In the meantime, I'll work on a PR to test that |
Can you try to do this (without breaking the tests)? Another option is to put getters on all static properties/methods and proxy them to the newest available version.
That won't work. We want to wrap the original class because in 90% of use cases decorator is higher-order component—not a monkeypatching pseudo-inheritance thing like |
I added some simple tests that compare the results of This implementation almost passes every test; I just need to fix this last one. I'll try to find a complete solution within the next few days; in the meantime, let me know if you think this is the right direction. Thanks! |
Direction seems right. 👍 |
#29 seems to have fixed the issue in your project. |
No worries about not using the changes I had -- my solution was incomplete Update: Upgrading to On Fri, Sep 25, 2015 at 3:06 AM, Dan Abramov [email protected]
|
Great. Should be fixed in |
(Note: I encountered this while using
react-transform-webpack-hmr
, but I believe the issue to be internal tocreateProxy
.)When using a
@decorator
function that copies the original component-class into a new one,static
properties specified using ES7 initializers are unaccounted for.For example, here's a slightly modified version of
App.js
fromreact-transform-boilerplate
:We expect the rendered output to look like this:

But instead we see this:

For some reason,
Counter.defaultProps
is not transferred in TypeScript's implementation of__extends
when it is defined with ES7 generators.It may have something to do with how
__extends
useshasOwnProperty
, but I'm not familiar enough with howreact-proxy
works under the hood to really take a stab at what might be going on, here.@decorator
, it works as expected.@decorator
to use ES6'sextends
, (i.e.class DerivedComponent extends Component ...
), it works as expected.defaultProps
after the decorator runs (i.e.Counter.defaultProps = ...
), it works as expected.I first encountered this problem when using
react-free-style
, which is written in TypeScript and provides a decorator function that extends components.The natural workaround is to avoid static ES7 property initializers, but many of us are already using them, as encouraged by React.
I forked
react-transform-boilerplate
to make it easier to reproduce the problem:git clone https://github.com/namuol/react-transform-boilerplate-es7-initializer-bug cd react-transform-boilerplate-es7-initializer-bug npm install npm start open http://localhost:3000
The text was updated successfully, but these errors were encountered: