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

Property was accessed through the prototype chain. Use 'decorate' instead #1506

Closed
LeonardoGentile opened this issue Apr 19, 2018 · 6 comments

Comments

@LeonardoGentile
Copy link

LeonardoGentile commented Apr 19, 2018

Hello,
since MobX 4 I'm (sometimes) having the following issue.
I'm declaring a computed property and an autorun attached to a React component, like this:

@inject(routerStore)
class RouteNode extends Component {
  
  // .....  

  @computed get isIntersection() {
    return this.routerStore.intersectionNode === this.nodeName;
  }

  componentDidMount() {
    this.autorunDisposer = autorun(() => {
      if (this.isIntersection) {
        this.setState({
          route: this.routerStore.route
        });
      }
    });
  }

  componentWillUnmount() {
    this.autorunDisposer();
  }
  
  // ....
}

Sometimes I receive this in the console:

Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[Autorun@163] Error: [mobx] Property 'isIntersection' of '[object Object]' was accessed through the prototype chain. Use 'decorate' instead to declare the prop or access it statically through it's owner

So probably I should not declare @computed get isIntersection() on the component class but somehow use decorate?

The issue seems similar to #1427 but it's not exactly clear to me how I could solve it in this case 🤔

@urugator
Copy link
Collaborator

I can't replicate https://codesandbox.io/s/rl5z5xno9p
Can you set up a reproduction?
Do you extend from a custom Component or something like that?

@mweststrate
Copy link
Member

mweststrate commented Apr 19, 2018 via email

@LeonardoGentile
Copy link
Author

Full implementation here

@mweststrate yes indeed this happen during HMR!

@AmazingTurtle
Copy link
Contributor

AmazingTurtle commented Apr 27, 2018

I'm having the same errors with HMR.
Using [email protected], [email protected], [email protected].

Following babel plugins:

"plugins": [
  [
    "import",
     {
      "libraryName": "antd",
      "libraryDirectory": "lib",
      "style": "css"
    }
  ],
  "transform-runtime",
  "lodash",
  "transform-decorators-legacy",
  "extract-hoc/babel",
  "react-hot-loader/babel"
]

Following loaders for happypack were used:

[
    {
        loader: 'tslint-loader',
        options: {
            typeCheck: true,
            getCustomTransformers: () => ({
                before: [tsImportPluginFactory({
                    libraryName: 'antd',
                    libraryDirectory: 'es',
                    style: 'css',
                })]
            })
        },
        enforce: 'pre'
    },
    {
        loader: 'babel-loader'
    },
    {
        loader: 'ts-loader',
        options: {
            happyPackMode: true
        }
    }
]

These are my entrypoints

entry: [
    'webpack/hot/only-dev-server',
    'webpack-dev-server/client?http://localhost:3000',
    'react-hot-loader/patch',
    'url-search-params-polyfill',
    './src/index'
],

@mweststrate
Copy link
Member

decorators and react hot loader has always been troublesome, and I gave up on it a few years ago :). That being said, if changing the above error to a warning fixes the problems, a PR for that will probably be accepted

@mweststrate
Copy link
Member

Released as 4.3.0

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

4 participants