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

Does not catch errors inside components that are decorated #20

Closed
qimingweng opened this issue Dec 26, 2015 · 7 comments
Closed

Does not catch errors inside components that are decorated #20

qimingweng opened this issue Dec 26, 2015 · 7 comments

Comments

@qimingweng
Copy link

This is interesting, I have been debugging this for a while, but I've noticed that when a component is wrapped by a decorator, thrown errors in its render function do not get caught!

// index.js

require('!!file?name=index.html!../index.html');

import React from 'react';
import ReactDOM from 'react-dom';

const mountNode = document.getElementById('app');

const loading = Component => {
  return class extends React.Component {
    render() {
      return <Component/>;
    }
  };
};

@loading
class App extends React.Component {
  render() {
    throw new Error('hello');

    return <div>
      App2
    </div>;
  }
}

ReactDOM.render(
  <App/>,
  mountNode
);

This is my babel config:

// babel config

const babelConfig = {
  presets: ['react', 'es2015', 'stage-0'],
  env: {
    development: {
      presets: ['react-hmre'],
    },
  },
};
@qimingweng
Copy link
Author

This is the full project I'm using, to reproduce.

https://github.com/qimingweng/react-transform-catch-errors-bug

@gaearon
Copy link
Owner

gaearon commented Dec 26, 2015

cc @thejameskyle

@jamiebuilds
Copy link
Collaborator

Decorators are not yet supported in Babel 6. Track https://phabricator.babeljs.io/T2645

@qimingweng
Copy link
Author

@thejameskyle I see. I was using https://www.npmjs.com/package/babel-plugin-transform-decorators-legacy to get the decorators to work again.

I have two questions, if you'll indulge me:

  1. Does react-transform run before other babel plugins? Is there a way to specify which order babel plugins are used? That way, perhaps I can run transform-decorators-legacy before running react-transform and then get this feature back.
  2. The hot loading module still works with transform-decorators-legacy, any thoughts as to why this module would be different?

@qimingweng
Copy link
Author

And side note, changing the syntax from decorator to regular function application does indeed allow this package to work again.

@jamiebuilds
Copy link
Collaborator

Does react-transform run before other babel plugins? Is there a way to specify which order babel plugins are used?

That's not really how it works, all plugins get run at the same time

@qimingweng
Copy link
Author

@thejameskyle Thanks for clearing that up. Reading https://phabricator.babeljs.io/T6730 it makes a lot more sense now.

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

3 participants