Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

react-apollo swallows render errors of wrapped components #347

Closed
bessey opened this issue Nov 29, 2016 · 4 comments
Closed

react-apollo swallows render errors of wrapped components #347

bessey opened this issue Nov 29, 2016 · 4 comments
Assignees
Labels

Comments

@bessey
Copy link

bessey commented Nov 29, 2016

Steps to Reproduce

My case is produced as follows:

  • Have a component that will raise an error in its render(), when a query is complete e.g.
render () {
  let {loading} = this.props.data 
  return (
    { loading ? null : <RealComponent blah={this.thisMethodIsntReal()} /> }
  )
}
  • Wrap it with the graphql HOC (import { graphql } from 'react-apollo')

Note that I haven't tried simplifying this test case and its possible less setup is required.

Buggy Behavior

Rather than raising this.thisMethodIsntReal is not a function, Apollo catches the error, and passes it into the component as data, wiping out the actual data returned from the query. In doing so it (likely) causes a different obscure error in your component, because the component depended on the now missing data.

Here's my example with a debugger in render() to show the contents of this.props.data

image

Expected Behavior

Apollo should not catch errors it did not cause, this error should propagate to the console and so the second state, with no data, should never be reached.

Version

@tmeasday tmeasday added the bug label Nov 29, 2016
@tmeasday
Copy link
Contributor

Thanks @bessey. This is an issue a few have run into, thanks for the simple repro.

@bessey
Copy link
Author

bessey commented Nov 29, 2016

This is my current workaround, which may be helpful to others. I wrap components in a HOC that doesn't swallow the error so its apollo(throwApolloError(component))

https://gist.github.com/bessey/926cdb3e383b406e7f546c6f4dd55a8a

@tmeasday
Copy link
Contributor

tmeasday commented Dec 2, 2016

I think this should be fixed by [email protected]. Can you give it a try and let me know?

@bessey
Copy link
Author

bessey commented Dec 2, 2016 via email

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

No branches or pull requests

2 participants