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

Pre-release 0.8.0, problem with the context #608

Closed
oliviertassinari opened this issue May 4, 2015 · 9 comments
Closed

Pre-release 0.8.0, problem with the context #608

oliviertassinari opened this issue May 4, 2015 · 9 comments
Labels
core Infrastructure work going on behind the scenes

Comments

@oliviertassinari
Copy link
Member

I'm struggling to migrate to the new version.

The context is undefined in a lot of components (this.context), not every one. Any idea why ?
I'm using React 0.13.2 and Webpack to build my application.

And, shounldn't we use isRequired?

  contextTypes: {
    muiTheme: React.PropTypes.object.isRequired
  },
@oliviertassinari oliviertassinari changed the title Pre-release 0.8.0 Pre-release 0.8.0, problem with the context May 4, 2015
@mmrtnz
Copy link
Contributor

mmrtnz commented May 5, 2015

Hi @oliviertassinari, I have a couple of questions that can help me get an idea of what's happening:

  • Can you verify that this.context is undefined and not this.context.muiTheme?
  • Do you receive an warning with the following message: Warning: owner-based and parent-based contexts differ...?
  • Also can you specify what components are experiencing this error?

One thing we've noticed is having multiple versions of react in your node_modules causes muiTheme to be undefined. Also you are right that we should be using isRequired. We simply glossed over it during development. However, I am not sure if this will solve your problem, but it's worth a try.

@oliviertassinari
Copy link
Member Author

  • I have a warning like Warning: owner-based and parent-based ...
  • I have noticed this problem on the component Paper and Dialog-Window so far.

Oh, indeed, I have two versions of React. I will try with only one.

Using isRequired doesn't solve my problem but would have saved me a lot of time, figuring out the origin of the problem.

@oliviertassinari
Copy link
Member Author

I confirm, I solved the problem by using only one version of React.

thanks @mmrtnz

@mgmartel
Copy link

mgmartel commented May 7, 2015

For other people looking for a solution: with webpack you can force all libraries to use the same version of React by setting up an alias. See this blog: http://www.justincarmony.com/blog/2015/04/02/webpack-react-multiple-versions-issues/

Add this to your webpack.config.js for a quick fix:

module.exports = {
    // ... other settings ...

    resolve: {
        // ...other resolve settings ...
        alias: {
            "react": __dirname + '/node_modules/react',
            "react/addons": __dirname + '/node_modules/react/addons',
        }
    }

    // ... other settings ...
}

@ghost
Copy link

ghost commented Sep 14, 2015

@oliviertassinari How do you set only one React version? Now I'm using webpack and react version is 0.1.3.3.
let React = require('react');
let mui = require('material-ui');
I use these to import them, and the build file has two React.version.
thanks

@oliviertassinari
Copy link
Member Author

@xushao0305 I had one react directory at the first level of node_modules and a second one at the level of material-ui. I removed the second one.

@ghost
Copy link

ghost commented Sep 14, 2015

@oliviertassinari Fine! It works after I remove the React directory of material-ui. Thanks.
But in production env.We use npm install to get material-ui, and it take the second react, Is there some way to remove it automatic?

@oliviertassinari
Copy link
Member Author

The react folder appears inside material-ui if you run npm install in the material-ui directory.
npm do a flat dependancy resolution. This means that after running npm install at the root of your project, you should have only one react folder.

@ghost
Copy link

ghost commented Sep 14, 2015

@oliviertassinari OK. thanks olivier

@oliviertassinari oliviertassinari added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 25, 2022
@zannager zannager added core Infrastructure work going on behind the scenes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

No branches or pull requests

4 participants