Skip to content
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

Doesn't work when used together with babel-plugin-transform-decorators-legacy #26

Closed
smashercosmo opened this issue Mar 15, 2016 · 4 comments · Fixed by #27
Closed

Doesn't work when used together with babel-plugin-transform-decorators-legacy #26

smashercosmo opened this issue Mar 15, 2016 · 4 comments · Fixed by #27

Comments

@smashercosmo
Copy link
Contributor

Yep, I know that both transforms are use-on-your-own-risk kind of thing) But just FYI, these transforms don't work together. You get this error in console:

Uncaught TypeError: Cannot set property render of #<ComponentName> which has only a getter

removing either babel-plugin-transform-decorators-legacy or react-transform-catch-errors fixes the issue.

@gaearon
Copy link
Owner

gaearon commented Mar 15, 2016

Would you like to take a stab at fixing this? I would presume that using Object.defineProperty might work instead.

@smashercosmo
Copy link
Contributor Author

The good news is that, yes, it did the trick) The bad news is that I have absolutely no idea, what's going on here :) So, of course I can just submit a PR without digging into this, but it would be awesome if you could give me some hints) Do you have any idea where does this error come from? Why does render property on ReactClass prototype become unwritable?

@gaearon
Copy link
Owner

gaearon commented Mar 16, 2016

I would suggest you to refer to Object.defineProperty() docs.

Why does render property on ReactClass prototype become unwritable?

My guess is that some of the decorators you use return a get descriptor rather than a value property descriptor. (Are you using some decorator for autobinding?) When a property is defined using a get descriptor, you can’t use assignment operator on this property. However, unless the descriptor has configurable: false, you can redefine this property again with Object.defineProperty(). Again, the docs should give you a better idea.

Finally, I wouldn’t recommend using decorators before you have a good idea about how they work. Understanding Object.defineProperty() is essential to understanding decorators.

@smashercosmo
Copy link
Contributor Author

Yes, you're right, it's autobind-decorator, that redefines render property. Now I get it. Thank you. I'll submit PR with a fix tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants