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

render arrow functions breaking in 2.0.0-beta.17 #828

Closed
johnlindquist opened this issue Jan 19, 2017 · 9 comments · May be fixed by RiftNemesis/next.js#558
Closed

render arrow functions breaking in 2.0.0-beta.17 #828

johnlindquist opened this issue Jan 19, 2017 · 9 comments · May be fixed by RiftNemesis/next.js#558
Assignees

Comments

@johnlindquist
Copy link

The code below

  • Works in "1.2.3"
  • Breaks in "2.0.0-beta.17"
import React, { Component } from 'react'

export default class App extends Component {
    render = () => <div>Hi</div> //notice the arrow function
}

Errors:

warning.js?1292f09:36 Warning: App(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
warning.js?1292f09:36 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
 (client) " data-reactid="1"><!-- react-empty: 2 -
 (server) " data-reactid="1"><div data-reactid="2"
@arunoda
Copy link
Contributor

arunoda commented Jan 21, 2017

Something definitely wrong here.
Following code prints it as "Hi"

import React, { Component } from 'react'

export default class App extends Component {
  render() {
    return (<div>Something else</div>)
  }
  render = () => <div>Hi</div> //notice the arrow function
}

@arunoda
Copy link
Contributor

arunoda commented Jan 21, 2017

@nkzawa this is related to our client side patch-react.js. It works when commented out.
I'll find a fix today.

@arunoda
Copy link
Contributor

arunoda commented Jan 21, 2017

It also seems like HMR is also not working for class properties. @johnlindquist could you check that with v1.2.3

@johnlindquist
Copy link
Author

@arunoda
Changed

import { Component } from 'react'

export default class extends Component {
    state = { message: 'foo' } //notice foo

    render = () => <div>
        {this.state.message}
    </div>
}

To:

import { Component } from 'react'

export default class extends Component {
    state = { message: 'bar' } //notice bar

    render = () => <div>
        {this.state.message}
    </div>
}

And the page updated without refreshing in 1.2.3. So it looks good to me.

@arunoda
Copy link
Contributor

arunoda commented Jan 21, 2017

@johnlindquist Okay. I'll look into that too.

@nkzawa
Copy link
Contributor

nkzawa commented Jan 21, 2017

btw just curious why you'd like to do this since render = () => <div>Hi</div> wouldn't be performant.

@avanslaars
Copy link
Contributor

@nkzawa curious as to what the specific performance implications are. Would you be able explain or point to a resource so I can understand? Thanks!

@nkzawa
Copy link
Contributor

nkzawa commented Jan 21, 2017

@avanslaars because it's transpiled like the following:

function Component () {
  this.render = function () {}
}

@avanslaars
Copy link
Contributor

@nkzawa Thanks!

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants