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

Hot reload and graphql() React component #764

Closed
zdne opened this issue Oct 12, 2016 · 2 comments
Closed

Hot reload and graphql() React component #764

zdne opened this issue Oct 12, 2016 · 2 comments

Comments

@zdne
Copy link

zdne commented Oct 12, 2016

I have noticed that a react component "with data" obtained by calling graphql(query)(component) doesn't work with HMR. Is this a known issue?

Failing Example

Any change to the SampleComponent (e.g. modifying text in the <p> element) isn't reflected in in HMR (I can se the module gets updated but browser doesn't render it).

class SampleComponent extends React.Component {
  render() {
    let email = 'n/a'
    if (this.props.data.launch_contact) {
      email = this.props.data.launch_contact.email
    }

    return(
      <div>
        <p>Email is '{email}'.</p>
      </div>
    )
  }
}



const MyQuery = gql`
query MyQuery {
  launch_contact(id: 2) {
    email
  }
}
`

const SampleComponentWithData = graphql(MyQuery)(SampleComponent)

...

class TopLevelComponent extends React.Component {
  render() {
    return (
      <ApolloProvider client={client}>
        <SampleComponentWithData />
      </ApolloProvider>
    )
  }
}

Working Example

If I wrap SampleComponentWithData within another component the HMR work.

...

class WrapperComponent extends React.Component {
  render() {
    return(
      <div>
        <SampleComponentWithData /> 
        <p>Any update here gets hot-reloaded correctly!</p>
      </div>
    )
  }
}

class TopLevelComponent extends React.Component {
  render() {
    return (
      <ApolloProvider client={client}>
        <WrapperComponent />
      </ApolloProvider>
    )
  }
}

HMR also works if I use SampleComponent directly (without Apollo query).

@stubailo
Copy link
Contributor

Could this be the same as apollographql/react-apollo#174?

Either way, this should in in react-apollo because it probably has to do with that integration. Thanks for providing a detailed discussion, let's keep talking there.

@zdne
Copy link
Author

zdne commented Oct 14, 2016

Thanks @stubailo I'll move there.

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

No branches or pull requests

2 participants