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

Broken/outdated 'this' in class properties #435

Closed
awv-inf opened this issue Dec 2, 2016 · 6 comments
Closed

Broken/outdated 'this' in class properties #435

awv-inf opened this issue Dec 2, 2016 · 6 comments

Comments

@awv-inf
Copy link

awv-inf commented Dec 2, 2016

Hot loader currently seems to confuse 'this' in class property methods. It points at an older class instance without refs or locals.

class App extends React.PureComponent {
    componentDidMount() {
        // 'view' gets stored and is available
        this.view = this.refs.view.getInterface();
        this.view.scene.add(this.props.session.pool);
    }
    onDoubleClick = () => {
        // here 'this' points to a version of 'App' without 'view' and 'this.refs' is empty
        this.view.updateBounds().controls.focus().zoom();
    }
    render() {
        return (
            <main className={this.props.classes.main}>
                <Canvas
                    style={{ position: 'absolute', top: 0, left: 0 }}
                    onDoubleClick={this.onDoubleClick}>
                    <View ref="view" up={ [0, 1, 0] } />

screencap

Environment

React Hot Loader version: 3.0.0-beta.6

Run these commands in the project folder and fill in their results:

  1. node -v: v7.2.0
  2. npm -v: 3.10.5

Then, specify:

  1. Operating system: Windows 10
  2. Browser and version: Chrome beta 55
@calesce
Copy link
Collaborator

calesce commented Dec 2, 2016

Thanks for the issue. Can you share your Babel config?

@awv-inf
Copy link
Author

awv-inf commented Dec 2, 2016

Certainly, https://gist.github.com/awv-inf/257464c57fd19b656858c6ffd5a87c91

The babel config is in the first blob. It applies to env.dev only, where react-hot-loader is inlined.

@calesce
Copy link
Collaborator

calesce commented Dec 2, 2016

You may need to add transform-es2015-classes (or es2015 preset) to your dev config, as this could be related to #313.

@awv-inf
Copy link
Author

awv-inf commented Dec 3, 2016

This worked indeed, thanks! With the downside of course that now we have transpiled classes. Is this a browser bug or will it get fixed in RHL?

@calesce
Copy link
Collaborator

calesce commented Dec 3, 2016

Fixed in RHL. It seems most likely that the issue is at the react-proxy layer. Its tests are run against both transpiled and built-in classes, so I'm not sure what's causing it to fail.

@calesce
Copy link
Collaborator

calesce commented Dec 3, 2016

Going to close this out because you got it working and the underlying issue is #313.

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

No branches or pull requests

2 participants